IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C++ Discussion :

à la compilation : error: expected ‘,’ or ‘..’ before ‘&’ token|


Sujet :

C++

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 79
    Points : 42
    Points
    42
    Par défaut à la compilation : error: expected ‘,’ or ‘..’ before ‘&’ token|
    Bonjour à tous,

    Je reste depuis tout à l'heure sur une erreur semble t-il de syntaxe :s

    Je vous fais voir mon code :

    classe Entier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    // Entier.h
    #ifndef E_H
    #define E_H
    #include "Fraction.h"
    #include <iostream>
    using namespace std;
     
    class Entier {
      int nombre;
      public :
    //constructeurs
       Entier(const int=0);
     
    //Opérateuns d'action
       Entier& operator*(const Fraction&);
       Entier& operator*(const Entier&);
       Entier& operator+(const Fraction&);
       Entier& operator+(const Entier&);
       Entier& operator-(const Fraction&);
       Entier& operator-(const Entier&);
       Entier& operator/(const Fraction&);
       Entier& operator/(const Entier&);
       Entier& operator=(const Fraction&);
       Entier& operator=(const Entier&);
    //Opérateurs de test
       bool operator>(const Fraction&);
       bool operator>(const Entier&);
       bool operator>=(const Fraction&);
       bool operator>=(const Entier&);
       bool operator<(const Fraction&);
       bool operator<(const Entier&);
       bool operator<=(const Fraction&);
       bool operator<=(const Entier&);
       bool operator==(const Fraction&);
       bool operator==(const Entier&);
       bool operator!=(const Fraction&);
       bool operator!=(const Entier&);
    //Fonctions amies
       friend ostream& operator<<(ostream&, Entier&);   //opérateurs de flux (ex : cout)
       friend istream& operator>>(istream& , Entier&);  //opérateurs de flux (ex : cin)
    };
    #endif
    et classe Fraction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    #ifndef F_H
    #define F_H
    #include "Entier.h"
    #include <iostream>
    using namespace std;
     
    //---------------------------------------------------------------------------
     
    class Fraction {
       int Num;
       int Denom;
    public :
    //constructeurs
       Fraction(const int, const int);
       Fraction(const int);
       Fraction();
    //Opérateuns d'action
       Fraction& operator*(const Fraction&);
       Fraction& operator*(const Entier&);
       Fraction& operator+(const Fraction&);
       Fraction& operator+(const Entier&);
       Fraction& operator-(const Fraction&);
       Fraction& operator-(const Entier&);
       Fraction& operator/(const Fraction&);
       Fraction& operator/(const Entier&);
       Fraction& operator=(const Fraction&);
       Fraction& operator=(const Entier&);
    //Opérateurs de test
       bool operator>(const Fraction&);
       bool operator>(const Entier&);
       bool operator>=(const Fraction&);
       bool operator>=(const Entier&);
       bool operator<(const Fraction&);
       bool operator<(const Entier&);
       bool operator<=(const Fraction&);
       bool operator<=(const Entier&);
       bool operator==(const Fraction&);
       bool operator==(const Entier&);
       bool operator!=(const Fraction&);
       bool operator!=(const Entier&);
    //Fonctions amies
       friend ostream& operator<<(ostream&, Fraction&);   //opérateurs de flux (ex : cout)
       friend istream& operator>>(istream& , Fraction&);  //opérateurs de flux (ex : cin)
       friend int Pgcd(const int&,const int&); // trouve le plus grand diviseur commun entre i1 et i2
    //Fonctions diverses
       Fraction& Simp();                      //Simplifie une fraction
       Fraction& Puis(const int&);            //comme un opérateur puissance
       Fraction& Inv();                       //Inverse la fraction
       int Signe();                           // 1 = positif ou nul      -1 = négatif
       void MemeDenom(Fraction&,Fraction&);   // met les deux fractions au meme dénominateur
       int ValAprox();
    };
    #endif
    D'après ce que j'ai vu cela vient des appels à Entier dans la classe Fraction et vice versa, je ne comprends pas l'erreur étant donné que j'ai bien mis mes includes entre les ifndef.
    L'erreur est exactement la suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    /home/guillaume/Documents/M1/projetcpp/ProjetC++/Fraction.h|19|error: ISO C++ forbids declaration of ‘Entier’ with no type|
    Elle se répète 22 fois à chaque appel à Fraction dans Entier et vice versa

    Merci d'avance pour votre aide

  2. #2
    Expert éminent sénior
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 614
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 614
    Points : 30 626
    Points
    30 626
    Par défaut
    Salut,

    Tu as, tout simplement, un problème d'inclusion cycliques...

    En effet, ton fichier Entier.h inclut le fichier Fraction.h, qui inclut le fichier Entier.h qui... (tu comprend le principe )

    Ce qu'il faut, c'est briser ce cercle vicieux. Par chance, il existe une entrée de la FAQ qui explique comment résoudre ce problème
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 79
    Points : 42
    Points
    42
    Par défaut
    merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. error: expected ']' before ';' token
    Par bertry dans le forum Débuter
    Réponses: 3
    Dernier message: 27/03/2015, 10h13
  2. error: expected ')' before '*' token
    Par imou222 dans le forum C
    Réponses: 3
    Dernier message: 08/08/2013, 12h58
  3. Réponses: 2
    Dernier message: 16/11/2011, 11h25
  4. Réponses: 3
    Dernier message: 08/03/2011, 23h04
  5. Réponses: 4
    Dernier message: 14/04/2010, 09h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo