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

SL & STL C++ Discussion :

erreur de compilation


Sujet :

SL & STL C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 11
    Par défaut erreur de compilation
    Bonjour à tous

    j'ai un problème de compilation d'un projet dont je dois prendre la suite. Je fais la compilation avec g++, sous linux.

    Toutes les erreurs interviennent dans deux fichiers *.hpp qui contiennent les déclarations et les définitions de classes templates. Il n'y a pas de templates dans le reste du code, donc je pense que ça vient de là.

    g++ -Wno-non-template-friend -O4 -c -o Component.o Component.cpp
    In file included from /usr/include/c++/4.2/backward/iostream.h:31,
    from Component.cpp:3:
    /usr/include/c++/4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
    In file included from Array1D.hpp:19,
    from HashTable.hpp:16,
    from Component.cpp:7:
    Exception.h: In constructor ‘Exception::Exception()’:
    Exception.h:20: warning: deprecated conversion from string constant to ‘char*’
    In file included from HashTable.hpp:18,
    from Component.cpp:7:
    List.hpp: In destructor ‘List<T>::~List()’:
    List.hpp:101: error: ‘head’ was not declared in this scope
    List.hpp: In constructor ‘List<T>::List()’:
    List.hpp:251: error: ‘head’ was not declared in this scope
    List.hpp:251: error: ‘curr’ was not declared in this scope
    List.hpp:251: error: expected type-specifier before ‘Link’
    List.hpp:251: error: expected `;' before ‘Link’
    List.hpp: In copy constructor ‘List<T>::List(const List<T>&)’:
    List.hpp:260: error: ‘head’ was not declared in this scope
    List.hpp:260: error: ‘curr’ was not declared in this scope
    List.hpp:260: error: expected type-specifier before ‘Link’
    List.hpp:260: error: expected `;' before ‘Link’
    List.hpp: In member function ‘List<T>& List<T>::operator+=(const List<T>&)’:
    List.hpp:300: error: there are no arguments to ‘end’ that depend on a template parameter, so a declaration of ‘end’ must be available
    List.hpp:300: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
    Je crois comprendre que les erreurs viennent de mauvaises définitions de certaines variables, mais je vois pas comment les résoudre.
    Est-ce que ca vient du fait que les classes sont définies et déclarées dans le même fichiers? Est ce qu'il me manque des librairies?

  2. #2
    Membre éclairé Avatar de Trunks
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2004
    Messages
    534
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2004
    Messages : 534
    Par défaut
    Remplace les headers C++

    par

    Par exemple

    par

    S'il s'agit d'un header de type C par contre, comme <stdlib.h>, tu peux remplacer par <cstdlib> pour la plupart il me semble.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 11
    Par défaut
    Bonjour,

    voilà j'ai fait ce que vous m'avez dit. maintenant je me retrouve avec des erreurs du type :

    In file included from Material.h:5,
    from Component.h:7,
    from Component.cpp:10:
    Physical.h:29: error: ISO C++ forbids declaration of ‘ostream’ with no type
    Physical.h:29: error: ‘ostream’ is neither function nor member function; cannot be declared friend
    Physical.h:29: error: expected ‘;’ before ‘&’ token
    Physical.h:49: error: ‘ostream’ has not been declared
    Physical.h:49: error: ‘cout’ was not declared in this scope



    j'ai essayé d'inclure ostream et istream mais rien n'y fait : que veut dire :
    ISO C++ forbids declaration of ‘ostream’ with no type sachant que ma ligne de commande est :


    friend ostream & operator << (ostream &out, Color color);

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 11
    Par défaut template et g++
    Toutes les erreurs interviennent à nouveau dans mes deux fichiers *.hpp qui contiennent les déclarations et les définitions de classes templates. Je ne sais pas si j'ai oublié d'insérer une librairie ou si mes template sont mal déclarés ?

    un exemple de mon code :

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
     class Link
      {
      public:
     
        Link *nxt;
        Link *prev;
        T     element;
        Link(Link *p = 0, Link *n = 0){
          prev= p;
          nxt = n;
          if (prev)
    	prev->nxt = this;
          if (nxt)
    	nxt->prev = this;
        }
        ~Link(){
          if(prev)
    	prev->nxt = nxt;
          if(nxt)
    	nxt->prev = prev;
        }
      };
     
    protected:
     
      ListIterator(){ head = curr = 0; }
     
      Link *head;
      Link *curr;
     
      friend class List< T >;
      friend class FullList< T >;
     
    };
     
     
    template< class T > class List: public ListIterator< T >
    {
     
    public:
      List();
      List(const List &l);
      ~List(){ 
        flush();
        delete head;
      }
     
      List & operator = (const List &l);
      List & operator = (const ListIterator< T >&li);
      List   operator + (const List &l) const;
      List & operator +=(const List &l);
      T    & operator [](int index);
     
      void insert(const T &el);
      void insert(ListIterator< T > &li, const T &el);
      int  nElements() const;
      void remove();
      void remove(ListIterator< T > &li);
      void flush();
     
    protected:
      int nels;
      T **ptrArray;
     
    };
     
    template< class T > class FullList : public List< T >
    {
    public: 
     
      FullList():List< T >(){}
      FullList(const List< T > &list):List< T >(list){}
     
     
      FullList & operator = (const ListIterator< T > &li);
      int  search(const T &el);
      int  search(ListIterator< T >&, const T &el) const;
      void write(ostream &out = cout) const;
      void read(istream &in = cin);
     
      friend ostream & operator<<(ostream &out, const FullList< T > &l);
      friend istream & operator>>(istream &in, FullList< T > &l);
     
    };
     
     
    template< class T >
    inline T& ListIterator< T >::operator()() const
    {
      if (curr == head)
        throw Exception("No current element!");
      return curr->element;
    }
     
    template< class T >
    inline ListIterator< T >& ListIterator< T >::operator++()
    {
      curr = curr->nxt;
      return *this;
    }
     
    template< class T >
    inline ListIterator< T >& ListIterator< T >::operator--()
    {
      curr = curr->prev;
      return *this;
    }
    et j'obtiens des erreurs comme :

    List.hpp: In member function ‘void List<T>::flush()’:
    List.hpp:401: error: ‘curr’ was not declared in this scope
    List.hpp:401: error: ‘head’ was not declared in this scope
    List.hpp:403: error: ‘Link’ was not declared in this scope
    List.hpp:403: error: ‘tmp’ was not declared in this scope

  5. #5
    r0d
    r0d est déconnecté
    Membre expérimenté

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2004
    Messages
    4 290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2004
    Messages : 4 290
    Billets dans le blog
    2
    Par défaut
    Ta classe Link est coupée en deux: le }; juste avant protected: est en trop.

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 13
    Par défaut
    Non, elle a oublié le début du code. La classe Link est déclarée dans la déclaration d'une classe ListIterator:

    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
    54
    55
    56
    57
    58
    59
    template< class T > class ListIterator
    {
     
    public:
      ListIterator(const List< T > &list) : 
        head(list.head), 
        curr(list.curr) { }
     
      T            & operator()()const;
      ListIterator & operator++();
      ListIterator & operator--();
      ListIterator & operator=(const ListIterator< T > &li);
      int            operator!() const;
      int            operator==(const ListIterator&) const;
      int            operator!=(const ListIterator&) const;
     
      T  & current() const;
      int  last() const;
      int  header() const;
      T  & previous() const;
      int  first() const;
      int  end();
      T  & next() const;
      int  beginning();
     
      class Link
      {
      public:
     
        Link *nxt;
        Link *prev;
        T     element;
        Link(Link *p = 0, Link *n = 0){
          prev= p;
          nxt = n;
          if (prev)
    	prev->nxt = this;
          if (nxt)
    	nxt->prev = this;
        }
        ~Link(){
          if(prev)
    	prev->nxt = nxt;
          if(nxt)
    	nxt->prev = prev;
        }
      };
     
    protected:
     
      ListIterator(){ head = curr = 0; }
     
      Link *head;
      Link *curr;
     
      friend class List< T >;
      friend class FullList< T >;
     
    };

Discussions similaires

  1. Erreur de compilation après modification du Uses
    Par DevelOpeR13 dans le forum Langage
    Réponses: 5
    Dernier message: 30/10/2007, 14h23
  2. Réponses: 2
    Dernier message: 23/09/2003, 14h32
  3. Réponses: 10
    Dernier message: 22/09/2003, 21h58
  4. Réponses: 4
    Dernier message: 27/08/2003, 21h34
  5. Réponses: 2
    Dernier message: 04/03/2003, 23h24

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