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 :

problème avec mon vector d'enum


Sujet :

C++

  1. #1
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    1 299
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 299
    Par défaut problème avec mon vector d'enum
    Bonjour, j'ai le code suivant :

    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
     
    #include <vector>
     
    /* ident des mots-cles */
    typedef enum
    {
      KWDINITVALUE, /* valeur pour initialiser un tableau de IdentKwd               */
      KWDOK,        /* valeur pour specifier si un mot-cle a ete selectionne ou non */
      INFOOPERATEURDEBUT,
      INFOOPERATEURFIN,
      NC_CONFIG,
      NC_TITRE,
      NC_NCABLES,
     
      NB_KWD /* laisser cette valeur a la fin pour compter le nombre de mots-cles de l'enumeration !! */
    } IdentKwd;
     
    using namespace std;
     
    int main()
    {
      vector<IdentKwd> kwdOK(NB_KWD,KWDINITVALUE);
      return 0;
    }
    et visual 2005 me renvoie l'erreur suivante lors de la compilation :

    1>Compiling...
    1>main.cpp
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(610) : error C2838: 'iterator_category' : illegal qualified name in member declaration
    1> c:\program files\microsoft visual studio 8\vc\include\vector(501) : see reference to class template instantiation 'std::iterator_traits<_Iter>' being compiled
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1> d:\documents and settings\f284272\desktop\test\main.cpp(21) : see reference to function template instantiation 'std::vector<_Ty>::vector<IdentKwd>(_Iter,_Iter)' being compiled
    1> with
    1> [
    1> _Ty=IdentKwd,
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(610) : error C2146: syntax error : missing ';' before identifier 'iterator_category'
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(610) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(610) : error C2602: 'std::iterator_traits<_Iter>::iterator_category' is not a member of a base class of 'std::iterator_traits<_Iter>'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(610) : see declaration of 'std::iterator_traits<_Iter>::iterator_category'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(610) : error C2868: 'std::iterator_traits<_Iter>::iterator_category' : illegal syntax for using-declaration; expected qualified-name
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(611) : error C2838: 'value_type' : illegal qualified name in member declaration
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(611) : error C2146: syntax error : missing ';' before identifier 'value_type'
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(611) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(611) : error C2602: 'std::iterator_traits<_Iter>::value_type' is not a member of a base class of 'std::iterator_traits<_Iter>'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(611) : see declaration of 'std::iterator_traits<_Iter>::value_type'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(611) : error C2868: 'std::iterator_traits<_Iter>::value_type' : illegal syntax for using-declaration; expected qualified-name
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(612) : error C2838: 'difference_type' : illegal qualified name in member declaration
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(612) : error C2146: syntax error : missing ';' before identifier 'difference_type'
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(612) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(612) : error C2602: 'std::iterator_traits<_Iter>::difference_type' is not a member of a base class of 'std::iterator_traits<_Iter>'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(612) : see declaration of 'std::iterator_traits<_Iter>::difference_type'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(612) : error C2868: 'std::iterator_traits<_Iter>::difference_type' : illegal syntax for using-declaration; expected qualified-name
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(614) : error C2838: 'pointer' : illegal qualified name in member declaration
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(614) : error C2146: syntax error : missing ';' before identifier 'pointer'
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(614) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(614) : error C2602: 'std::iterator_traits<_Iter>::pointer' is not a member of a base class of 'std::iterator_traits<_Iter>'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(614) : see declaration of 'std::iterator_traits<_Iter>::pointer'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(614) : error C2868: 'std::iterator_traits<_Iter>::pointer' : illegal syntax for using-declaration; expected qualified-name
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(615) : error C2838: 'reference' : illegal qualified name in member declaration
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(615) : error C2146: syntax error : missing ';' before identifier 'reference'
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(615) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(615) : error C2602: 'std::iterator_traits<_Iter>::reference' is not a member of a base class of 'std::iterator_traits<_Iter>'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(615) : see declaration of 'std::iterator_traits<_Iter>::reference'
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\xutility(615) : error C2868: 'std::iterator_traits<_Iter>::reference' : illegal syntax for using-declaration; expected qualified-name
    1> with
    1> [
    1> _Iter=IdentKwd
    1> ]
    1>c:\program files\microsoft visual studio 8\vc\include\vector(501) : error C2664: 'void std::vector<_Ty>::_Construct<_Iter>(_Iter,_Iter,std::_Int_iterator_tag)' : cannot convert parameter 3 from 'int' to 'std::_Int_iterator_tag'
    1> with
    1> [
    1> _Ty=IdentKwd,
    1> _Iter=IdentKwd
    1> ]
    1> No constructor could take the source type, or constructor overload resolution was ambiguous
    une recherche sur le net du code erreur C2838 ne m'aide pas bcp. Avez-vous une idée pour corriger mon problème ?

    Merci d'avance

  2. #2
    Membre éclairé Avatar de thoratou
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    57
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 57
    Par défaut
    En C++ tu n'a pas besoin de faire un typedef avec ton enum. Essaye avec ca :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    enum IdentKwd
    {
      KWDINITVALUE, /* valeur pour initialiser un tableau de IdentKwd               */
      KWDOK,        /* valeur pour specifier si un mot-cle a ete selectionne ou non */
      INFOOPERATEURDEBUT,
      INFOOPERATEURFIN,
      NC_CONFIG,
      NC_TITRE,
      NC_NCABLES,
     
      NB_KWD /* laisser cette valeur a la fin pour compter le nombre de mots-cles de l'enumeration !! */
    };

  3. #3
    Membre expérimenté

    Inscrit en
    Mai 2005
    Messages
    132
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 132
    Par défaut
    Salut,

    ca marche

    vector < IdentKwd > kwdOK; // ( NB_KWD, KWDINITVALUE );
    Fredy

    (je l'ai essaye sous Linux)

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    1 299
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 299
    Par défaut
    Salut, OK j'ai changé mais le problème est toujours là...

  5. #5
    Membre expérimenté

    Inscrit en
    Mai 2005
    Messages
    132
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 132
    Par défaut
    Salut,

    aussi bonne .... je l'ai essaye encore une fois maintenant sous WinXP ( MSVC 6++, project win32 ) et on peut le compiler sans changement. Ce sera quelque chose avec MS VS 8 .... je sais pas ....

    Fredy

  6. #6
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    1 299
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 299
    Par défaut
    Re,

    c'est bizarre, le code suivante compile parfaitement :

    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
     
    #include <vector>
     
    using namespace std;
     
    /* ident des mots-cles */
    enum IdentKwd
    {
      KWDINITVALUE, /* valeur pour initialiser un tableau de IdentKwd               */
      KWDOK,        /* valeur pour specifier si un mot-cle a ete selectionne ou non */
      INFOOPERATEURDEBUT,
      INFOOPERATEURFIN,
      NC_CONFIG,
      NC_TITRE,
      NC_NCABLES,
     
      NB_KWD /* laisser cette valeur a la fin pour compter le nombre de mots-cles de l'enumeration !! */
    };
     
     
     
    int main()
    {
      vector<IdentKwd> kwdOK;
      kwdOK.resize(NB_KWD,KWDINITVALUE);
      return 0;
    }
    Merci Freedy.

  7. #7
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 395
    Par défaut
    Essayez ce petit changement:
    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    vector<IdentKwd> kwdOK(static_cast<int>(NB_KWD), KWDINITVALUE);
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

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

Discussions similaires

  1. Problème avec std::Vector
    Par mister3957 dans le forum SL & STL
    Réponses: 8
    Dernier message: 16/02/2006, 10h18
  2. [Mail] Problème avec mon script d'envoi de mail
    Par leroivert dans le forum Langage
    Réponses: 18
    Dernier message: 02/12/2005, 00h26
  3. Problème avec mon service mysql et PhpMyAdmin
    Par Fixazo dans le forum Outils
    Réponses: 1
    Dernier message: 28/08/2005, 18h02
  4. problème avec mon lecteur CD
    Par leo13 dans le forum Périphériques
    Réponses: 3
    Dernier message: 16/08/2005, 11h21
  5. Problème avec mon firewall ...
    Par Wis dans le forum Tomcat et TomEE
    Réponses: 15
    Dernier message: 06/04/2004, 08h46

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