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 :

classe enregistrement ne compile pas


Sujet :

C++

  1. #1
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut classe enregistrement ne compile pas
    bonjour � tous

    je ne comprend pas pourquoi il refuse ma classe enregistrement (je ne connais pas bien shared_ptr)

    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
    enregistrements.hpp
    #ifndef enregistrements_hpp
    #define enregistrements_hpp
     
    #include "commun.hpp"
     
    #include <string>
    #include <vector>
    enum class type{Taction,Tterminal,TnonTerminal,Tsynthese};
    enum class typeSynthese{synthC,synthA1,synthAprim,synthA2,
    			synthB,synthBprim};
     
    class enregistrement{
    public:
      virtual void affiche();
      virtual type quelType();
      virtual int getActionSemantique();
      virtual void setActionSemantique(int const &x);
      virtual SYMBOLE getSymbole();
      virtual void setSymbole(SYMBOLE const &x);
      virtual bool vaut(ULEX const &a);
      virtual bool estTerminal();
      virtual void ajoute(std::string const &x);
      virtual typeSynthese getNomSynthese();
      virtual void setNomSynthese(typeSynthese const &x);
    };
     
    class action:public enregistrement{
    public:
      void affiche();
      type quelType();// retourne toujours Taction
      std::string getA(int const &i);
      void setA(int const &i,std::string const &x);
      void ajoute(std::string const &x);
      int getActionSemantique();
      void setActionSemantique(int const &x);
    private:
      int actionSemantique;
      std::vector<std::string> Attr;
    };
     
    class terminal:public enregistrement{
    public:
      void affiche();
      type quelType();// retourne toujours Tterminal
      bool vaut(ULEX const &a);
      bool estTerminal();//retourne toujours true
      int getActionSemantique();//retourne toujours 0
      void setSymbole(SYMBOLE const &x);
      SYMBOLE getSymbole();
      std::string symbole2string();
    private:
      SYMBOLE X;
      ULEX term;
    };
     
    class nonTerminal:public enregistrement{
    public:
      void affiche();
      type quelType();// retourne toujours TnonTerminal
      void setSymbole(SYMBOLE const &x);
      SYMBOLE getSymbole();
      int getActionSemantique();//retourne toujours 0
      std::string getHerite(int i);
      void setHerite(int const &i,std::string const &x);
      void ajoute(std::string const &x);
      bool estTerminal();//retourne toujours false;
      std::string symbole2string();
    private:
      SYMBOLE X;
      std::vector<std::string>herite;
    };
     
    class synthese:public enregistrement{
    public:
      void affiche();
      type quelType();// retourne toujours Tsynthèse
      typeSynthese getNomSynthese();
      void setNomSynthese(typeSynthese const &x);
      std::string getA(int i);
      void setA(int const &i,std::string const &x);
      void ajoute(std::string const &x);
      int getActionSemantique();
      void setActionSemantique(int const &x);
      std::string symbole2string();
    private:
      std::vector<std::string>Attr;
      int actionSemantique;
      typeSynthese nomSynthese;
    };
    #endif
    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
    syntaxique.cpp
    #include <memory>
    #include <iostream>
    #include "syntaxique.hpp"
    #include "enregistrements.hpp"
     
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::shared_ptr<enregistrement>E;
      E=std::make_shared<enregistrement>(new terminal);
      E->setSymbole(SYMBOLE::dolar);
      pile.push_back(E);
      E=std::make_shared<enregistrement>(new nonTerminal);
      E->setSymbole(SYMBOLE::C);
      pile.push_back(E);
      E=std::make_shared<enregistrement>(new synthese);
      E->setNomSynthese(typeSynthese::synthC);
      E->ajoute("");
      E->ajoute("");
      pile.push_back(E);
    }
     
    void syntaxique::anaSynt(){
      uniLex l;
      l=pe.anaLex();
      a=l.getLex();
      X=std::make_shared<enregistrement>(pile[pile.size()-1]);
      while( ! X->vaut(ULEX::dolar)){
        if(X->vaut(a)){
          pile.pop_back();
          l=pe.anaLex();
          a=l.getLex();
        }
        else if(X->estTerminal())
          if(a==ULEX::dolar){
    	std::cerr<<"Fichier source inachevé"<<std::endl;
    	exit(1);
          }
          else{
    	std::cerr<<l.getLexeme()<<" inattendu"<<std::endl;
    	l=pe.anaLex();
    	a=l.getLex();
          }
        switch(X->getSymbole()){
        case SYMBOLE::C:
          if(a==ULEX::a){
    	//inachevé
          }
        }
      }
    }
    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
    108
    109
    110
    111
    112
    113
    $ g++ -c syntaxique.cpp
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = enregistrement; _Args = {terminal*}; _Tp = enregistrement]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = enregistrement; _Args = {terminal*}; _Tp = enregistrement; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<enregistrement>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {terminal*}; _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {terminal*}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {terminal*}; _Tp = enregistrement; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {terminal*}; _Tp = enregistrement]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {terminal*}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = enregistrement; _Args = {terminal*}]’
    syntaxique.cpp:8:50:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘enregistrement::enregistrement(terminal*)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement()12 | class enregistrement{
          |       ^~~~~~~~~~~~~~
    enregistrements.hpp:12:7: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(const enregistrement&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘terminal*’ to ‘const enregistrement&’
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(enregistrement&&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘terminal*’ to ‘enregistrement&&’
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = enregistrement; _Args = {nonTerminal*}; _Tp = enregistrement]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = enregistrement; _Args = {nonTerminal*}; _Tp = enregistrement; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<enregistrement>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {nonTerminal*}; _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {nonTerminal*}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {nonTerminal*}; _Tp = enregistrement; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {nonTerminal*}; _Tp = enregistrement]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {nonTerminal*}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = enregistrement; _Args = {nonTerminal*}]’
    syntaxique.cpp:11:53:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘enregistrement::enregistrement(nonTerminal*)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement()12 | class enregistrement{
          |       ^~~~~~~~~~~~~~
    enregistrements.hpp:12:7: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(const enregistrement&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘nonTerminal*’ to ‘const enregistrement&’
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(enregistrement&&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘nonTerminal*’ to ‘enregistrement&&’
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = enregistrement; _Args = {synthese*}; _Tp = enregistrement]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = enregistrement; _Args = {synthese*}; _Tp = enregistrement; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<enregistrement>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {synthese*}; _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {synthese*}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {synthese*}; _Tp = enregistrement; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {synthese*}; _Tp = enregistrement]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {synthese*}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = enregistrement; _Args = {synthese*}]’
    syntaxique.cpp:14:50:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘enregistrement::enregistrement(synthese*)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement()12 | class enregistrement{
          |       ^~~~~~~~~~~~~~
    enregistrements.hpp:12:7: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(const enregistrement&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘synthese*’ to ‘const enregistrement&’
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(enregistrement&&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘synthese*’ to ‘enregistrement&&’
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = enregistrement; _Args = {std::shared_ptr<enregistrement>&}; _Tp = enregistrement]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = enregistrement; _Args = {std::shared_ptr<enregistrement>&}; _Tp = enregistrement; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<enregistrement>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {std::shared_ptr<enregistrement>&}; _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {std::shared_ptr<enregistrement>&}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {std::shared_ptr<enregistrement>&}; _Tp = enregistrement; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<enregistrement>; _Args = {std::shared_ptr<enregistrement>&}; _Tp = enregistrement]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = enregistrement; _Alloc = std::allocator<enregistrement>; _Args = {std::shared_ptr<enregistrement>&}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = enregistrement; _Args = {std::shared_ptr<enregistrement>&}]’
    syntaxique.cpp:25:57:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘enregistrement::enregistrement(std::shared_ptr<enregistrement>&)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement()12 | class enregistrement{
          |       ^~~~~~~~~~~~~~
    enregistrements.hpp:12:7: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(const enregistrement&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘std::shared_ptr<enregistrement>’ to ‘const enregistrement&’
    enregistrements.hpp:12:7: note: candidate: ‘constexpr enregistrement::enregistrement(enregistrement&&)’
    enregistrements.hpp:12:7: note:   no known conversion for argument 1 from ‘std::shared_ptr<enregistrement>’ to ‘enregistrement&&’
    quelqu'un a une id�e?

  2. #2
    Invit�
    Invit�(e)
    Par d�faut
    Bonsoir,

    Ton probl�me vient des lignes o� tu utilises std::make_shared. Les param�tres que tu passes � cette fonction sont transmis au constructeur du type sp�cifi� en param�tre template.
    std::make_shared<Classe>(/* paramètres */) appelle en interne new Classe(/* ces mêmes paramètres std::forward-és */).

    Autrement dit ici, lorsque tu �cris std::make_shared<enregistrement>(new terminal);, elle appelle en interne new enregistrement(/* un pointeur sur terminal */), et donc :
    • tu ne cr�es pas un pointeur sur un terminal, mais sur un enregistrement ;
    • tu passes le pointeur new terminal au constructeur de la classe enregistrement,

    et ta classe enregistrement n'ayant aucun constructeur avec un terminal* en param�tre, tu te retrouves avec ce message d'erreur, en particulier :
    error: no matching function for call to �enregistrement::enregistrement(terminal*)�
    Ta ligne se corrige donc en :
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    X = std::make_shared<terminal>();
    M�me chose avec nonTerminal et synthese.

    En ce qui concerne le dernier X=std::make_shared<enregistrement>(pile[pile.size()-1]);, l� tu passes un carr�ment un std::shared_ptr<enregistrement> au constructeur.
    Pourquoi chercher � en cr�er un nouveau ? Alors que tu as juste � manipuler l'existant :
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    auto const & X = pile[pile.size()-1]; // ou pile.back();
    Quelques conseils pour finir :
    • marque const les fonctions membre qui ne modifient pas les membres ;
    • ajoute override aux fonctions membre virtuelles que tu red�finis dans les classes enfants ;
    • classe de base d'une hi�rarchie destructeur virtuel, suppression constructeur/op�rateur d'affectation par copie (s�mantique d'entit�) qui t'�vitera des fuites et probl�mes de slicing ;
    • utilise des noms de variable plus parlants qu'une seule lettre.

  3. #3
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    merci pour la r�ponse
    dans la pile, on a une collection h�t�rog�ne d'enregistrements (action,synth�se,terminal et nonTerminal)
    on ne sait pas ce que l'on va trouver au sommet de cette pile, c'est pourquoi j'ai utilis� "enregistrement".
    je voulais un pointeur E qui pointe, selon le somment de la pile, vers un objet d'une classe fille d'enregistrement (action, synth�se, terminal ou nonTerminal)
    devrais-je d�finir la pile comme �a:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    std::vector <enregistrement*>pile
    ou bien:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    std::vector<std::shared_ptr<enregistrement>> pile;
    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
    #ifndef SYNTAXIQUE_HPP
    #define SYNTAXIQUE_HPP
    #include <vector>
    #include <string>
    #include <memory>
    #include "lexical.hpp"
    #include "commun.hpp"
    #include "enregistrements.hpp"
     
    class syntaxique{
    public:
      syntaxique(std::string const& nomFichier);
      void anaSynt();
    private:
      lexical pe;
      std::vector<std::shared_ptr<enregistrement>> pile;
      void exec(int const &x);
      std::shared_ptr<enregistrement>X;
      ULEX a;
    };
    #endif
    sinon, peux-tu m'en dire plus sur "overide"?

  4. #4
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    voici enregistrements.cpp qui compile tr�s bien
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    #include <iostream>
    #include <string>
     
    #include "enregistrements.hpp"
     
    action::action(){}
     
    void action::affiche()const{
      std::cout<<"-----"<<std::endl
    	   <<"action"<<std::endl;
      for(int i=0;i<Attr.size();i++)
        std::cout<<Attr[i]<<std::endl;
      std::cout<<"-----"<<std::endl;
    }
     
    type action::quelType()const{
      return type::Taction;
    }
     
    std::string action::getA(int const &numAttr)const{
      return Attr[numAttr];
    }
     
    void action::ajoute(std::string const &numDonneeAction){
      Attr.push_back(numDonneeAction);
    }
     
    int action::getActionSemantique()const{
      return actionSemantique;
    }
     
    void action::setActionSemantique(int const &numAction){
      actionSemantique=numAction;
    }
     
    terminal::terminal(){}
     
    void terminal::affiche()const{
      std::cout<<"-----"<<std::endl
    	   <<symbole2string()<<std::endl
    	   <<"-----"<<std::endl;
    }
     
    type terminal::quelType()const{
      return type::Tterminal;
    }
     
    bool terminal::vaut(ULEX const &a)const{ /*l'identificateur "a" est indiqué
    					   ainsi dans le dragonbook, qui est
    					   l'unité lexical lu*/
      return (int)X==(int)a;//ainsi que X, qui est le sommet de la pile
    }
     
    bool terminal::estTerminal()const{
      return true;
    }
     
    int terminal::getActionSemantique()const{
      return 0;
    }
     
    void terminal::setSymbole(SYMBOLE const &x){ //mutateur de X
      X=x;
    }
     
    SYMBOLE terminal::getSymbole()const{
      return X;
    }
     
    std::string terminal::symbole2string()const{
      std::string convert;
      switch(X){
      case SYMBOLE::a:
        convert="a";
        break;
      case SYMBOLE::b:
        convert="b";
        break;
      case SYMBOLE::sep:
        convert="sep";
        break;
      case SYMBOLE::dolar:
        convert="$";
        break;
      }
      return convert;
    }
     
    nonTerminal::nonTerminal(){}
     
    void nonTerminal::affiche()const{
      std::cout<<"-----"<<std::endl
    	   <<symbole2string()<<std::endl;
      for(int i=0;i<herite.size();i++)
        std::cout<<herite[i]<<std::endl;
      std::cout<<"-----"<<std::endl;
    }
     
    type nonTerminal::quelType()const{
      return type::TnonTerminal;
    }
     
    void nonTerminal::setSymbole(SYMBOLE const &x){
      X=x;
    }
     
    int nonTerminal::getActionSemantique()const{
      return 0;
    }
     
    std::string nonTerminal::getHerite(int numAttr)const{
      return herite[numAttr];
    }
     
    void nonTerminal::setHerite(int const &numAttr,
    			    std::string const &valAttr){
      herite[numAttr]=valAttr;
    }
     
    void nonTerminal::ajoute(std::string const &valAttr){
      herite.push_back(valAttr);
    }
     
    bool nonTerminal::estTerminal()const{
      return false;
    }
     
    std::string nonTerminal::symbole2string()const{
      std::string convert;
      switch(X){
      case SYMBOLE::C:
        convert="C";
        break;
      case SYMBOLE::A:
        convert="A";
        break;
      case SYMBOLE::Aprim:
        convert="A'";
        break;
      case SYMBOLE::B:
        convert="B";
        break;
      case SYMBOLE::Bprim:
        convert="B'";
        break;
      }
      return convert;
    }
     
    synthese::synthese(){}
     
    void synthese::affiche()const{
      std::cout<<"-----"<<std::endl
    	   <<"synthèse "<<symbole2string()<<std::endl;
      for(int i=0;i<Attr.size();i++)
        std::cout<<Attr[i]<<std::endl;
    }
     
    type synthese::quelType()const{
      return type::Tsynthese;
    }
     
    std::string synthese::getA(int numAttr)const{
      return Attr[numAttr];
    }
     
    void synthese::setA(int const &numAttr,std::string const &valAttr){
      Attr[numAttr]=valAttr;
    }
     
    void synthese::ajoute(std::string const &valAttr){
      Attr.push_back(valAttr);
    }
     
    int synthese::getActionSemantique()const{
      return actionSemantique;
    }
     
    void synthese::setActionSemantique(int const &numAction){
      actionSemantique=numAction;
    }
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    commun.hpp
    #ifndef COMMUN_HPP
    #define COMMUN_HPP
     
    enum class SYMBOLE {a=0,b,sep,dolar,C,A,Aprim,B,Bprim,epsilone};
    enum class ULEX {a=0,b,sep,dolar};
     
    #endif
    j'ai modifi� syntaxique.cpp comme suit:

    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
    #include <memory>
    #include <iostream>
    #include "syntaxique.hpp"
    #include "enregistrements.hpp"
     
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::shared_ptr<terminal>E1;
      std::shared_ptr<nonTerminal>E2;
      std::shared_ptr<synthese>E3;
      E1=std::make_shared<terminal>(new terminal);
      E1->setSymbole(SYMBOLE::dolar);
      pile.push_back(E1);
      E2=std::make_shared<nonTerminal>(new nonTerminal);
      E2->setSymbole(SYMBOLE::C);
      pile.push_back(E2);
      E3=std::make_shared<synthese>(new synthese);
      E3->setNomSynthese(typeSynthese::synthC);
      E3->ajoute("");
      E3->ajoute("");
      pile.push_back(E3);
    }
     
    void syntaxique::anaSynt(){
      uniLex lu;
      lu=pe.anaLex();
      a=lu.getLex();/*"a" est indiqué ainsi dans le dragonbook, 
    		  c'est l'unité lexicale lu par l'analyseur lexical*/
      auto const & X = pile[pile.size()-1];
      while( ! X->vaut(ULEX::dolar)){// X, aussi comme a. Sommet de la pile
        if(X->vaut(a)){
          pile.pop_back();
          lu=pe.anaLex();
          a=lu.getLex();
        }
        else if(X->estTerminal())
          if(a==ULEX::dolar){
    	std::cerr<<"Fichier source inachevé"<<std::endl;
    	exit(1);
          }
          else{
    	std::cerr<<lu.getLexeme()<<" inattendu"<<std::endl;
    	lu=pe.anaLex();
    	a=lu.getLex();
          }
        switch(X->getSymbole()){
        case SYMBOLE::C:
          if(a==ULEX::a){
    	//inachevé
          }
        }
      }
    }

    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
    $ g++ -c syntaxique.cpp
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = terminal; _Args = {terminal*}; _Tp = terminal]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = terminal; _Args = {terminal*}; _Tp = terminal; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<terminal>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {terminal*}; _Tp = terminal; _Alloc = std::allocator<terminal>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = terminal; _Alloc = std::allocator<terminal>; _Args = {terminal*}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<terminal>; _Args = {terminal*}; _Tp = terminal; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<terminal>; _Args = {terminal*}; _Tp = terminal]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = terminal; _Alloc = std::allocator<terminal>; _Args = {terminal*}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = terminal; _Args = {terminal*}]’
    syntaxique.cpp:10:45:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘terminal::terminal(terminal*)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:46:3: note: candidate: ‘terminal::terminal()46 |   terminal();
          |   ^~~~~~~~
    enregistrements.hpp:46:3: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:44:7: note: candidate: ‘constexpr terminal::terminal(const terminal&)44 | class terminal:public enregistrement{
          |       ^~~~~~~~
    enregistrements.hpp:44:7: note:   no known conversion for argument 1 from ‘terminal*’ to ‘const terminal&’
    enregistrements.hpp:44:7: note: candidate: ‘constexpr terminal::terminal(terminal&&)’
    enregistrements.hpp:44:7: note:   no known conversion for argument 1 from ‘terminal*’ to ‘terminal&&’
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = nonTerminal; _Args = {nonTerminal*}; _Tp = nonTerminal]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = nonTerminal; _Args = {nonTerminal*}; _Tp = nonTerminal; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<nonTerminal>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {nonTerminal*}; _Tp = nonTerminal; _Alloc = std::allocator<nonTerminal>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = nonTerminal; _Alloc = std::allocator<nonTerminal>; _Args = {nonTerminal*}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<nonTerminal>; _Args = {nonTerminal*}; _Tp = nonTerminal; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<nonTerminal>; _Args = {nonTerminal*}; _Tp = nonTerminal]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = nonTerminal; _Alloc = std::allocator<nonTerminal>; _Args = {nonTerminal*}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = nonTerminal; _Args = {nonTerminal*}]’
    syntaxique.cpp:13:51:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘nonTerminal::nonTerminal(nonTerminal*)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:62:3: note: candidate: ‘nonTerminal::nonTerminal()62 |   nonTerminal();
          |   ^~~~~~~~~~~
    enregistrements.hpp:62:3: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:60:7: note: candidate: ‘nonTerminal::nonTerminal(const nonTerminal&)60 | class nonTerminal:public enregistrement{
          |       ^~~~~~~~~~~
    enregistrements.hpp:60:7: note:   no known conversion for argument 1 from ‘nonTerminal*’ to ‘const nonTerminal&’
    enregistrements.hpp:60:7: note: candidate: ‘nonTerminal::nonTerminal(nonTerminal&&)’
    enregistrements.hpp:60:7: note:   no known conversion for argument 1 from ‘nonTerminal*’ to ‘nonTerminal&&’
    In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                     from /usr/include/c++/9/bits/allocator.h:46,
                     from /usr/include/c++/9/memory:63,
                     from syntaxique.cpp:1:
    /usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = synthese; _Args = {synthese*}; _Tp = synthese]’:
    /usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = synthese; _Args = {synthese*}; _Tp = synthese; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<synthese>]’
    /usr/include/c++/9/bits/shared_ptr_base.h:548:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {synthese*}; _Tp = synthese; _Alloc = std::allocator<synthese>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:679:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = synthese; _Alloc = std::allocator<synthese>; _Args = {synthese*}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr_base.h:1344:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<synthese>; _Args = {synthese*}; _Tp = synthese; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/9/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<synthese>; _Args = {synthese*}; _Tp = synthese]’
    /usr/include/c++/9/bits/shared_ptr.h:701:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = synthese; _Alloc = std::allocator<synthese>; _Args = {synthese*}]’
    /usr/include/c++/9/bits/shared_ptr.h:717:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = synthese; _Args = {synthese*}]’
    syntaxique.cpp:16:45:   required from here
    /usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to ‘synthese::synthese(synthese*)145 |  noexcept(noexcept(::new((void *)__p)
          |                    ^~~~~~~~~~~~~~~~~~
      146 |        _Up(std::forward<_Args>(__args)...)))
          |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from syntaxique.hpp:8,
                     from syntaxique.cpp:3:
    enregistrements.hpp:80:3: note: candidate: ‘synthese::synthese()80 |   synthese();
          |   ^~~~~~~~
    enregistrements.hpp:80:3: note:   candidate expects 0 arguments, 1 provided
    enregistrements.hpp:78:7: note: candidate: ‘synthese::synthese(const synthese&)78 | class synthese:public enregistrement{
          |       ^~~~~~~~
    enregistrements.hpp:78:7: note:   no known conversion for argument 1 from ‘synthese*’ to ‘const synthese&’
    enregistrements.hpp:78:7: note: candidate: ‘synthese::synthese(synthese&&)’
    enregistrements.hpp:78:7: note:   no known conversion for argument 1 from ‘synthese*’ to ‘synthese&&’
    une id�e?

  5. #5
    Invit�
    Invit�(e)
    Par d�faut
    Citation Envoy� par matser Voir le message
    devrais-je d�finir la pile comme �a:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    std::vector <enregistrement*>pile
    ou bien:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    std::vector<std::shared_ptr<enregistrement>> pile;
    De base, je dirais plut�t un std::vector<std::unique_ptr<enregistrement>> � moins que tu aies besoin de partager la responsabilit�, auquel cas avec un std::shared_ptr.
    (Avec son homologue std::make_unique qui fonctionne de la m�me mani�re.)
    std::unique_ptr n'�tant pas copiable, il faudra faire attention � certaines lignes comme :
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    pile.push_back(E1); // copie !
    � passer en
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    pile.push_back( std::move(E1) ); // déplacement ok
    Citation Envoy� par matser Voir le message
    sinon, peux-tu m'en dire plus sur "overide"?
    (override avec deux � r �.) Cf. ce sujet de FAQ.

    Concernant la � nouvelle � erreur, on en revient � mon premier message. std::make_shared effectue elle-m�me le new. Ce n'est pas � toi de le faire. Et les param�tres d'entr�es de la fonction sont transmis au constructeur :

    std::make_shared<terminal>(new terminal); => new terminal(new terminal) en interne.

    Tes diff�rents constructeurs ne prennent aucun param�tre, donc laisse les parenth�ses vides.

  6. #6
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    merci Winjerome.
    je ne savais pas que c'�tait un appel au constructeur.
    j'ai modifi� syntaxique.cpp ainsi:
    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
    #include <memory>
    #include <iostream>
    #include "syntaxique.hpp"
    #include "enregistrements.hpp"
     
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::shared_ptr<terminal>E1;
      std::shared_ptr<nonTerminal>E2;
      std::shared_ptr<synthese>E3;
      E1=std::make_shared<terminal>();
      E1->setSymbole(SYMBOLE::dolar);
      pile.push_back(E1);
      E2=std::make_shared<nonTerminal>();
      E2->setSymbole(SYMBOLE::C);
      pile.push_back(E2);
      E3=std::make_shared<synthese>();
      E3->setNomSynthese(typeSynthese::synthC);
      E3->ajoute("");
      E3->ajoute("");
      pile.push_back(E3);
    }
     
    void syntaxique::anaSynt(){
      uniLex lu;
      lu=pe.anaLex();
      a=lu.getLex();/*"a" est indiqué ainsi dans le dragonbook, 
    		  c'est l'unité lexicale lu par l'analyseur lexical*/
      auto const & X = pile[pile.size()-1];
      while( ! X->vaut(ULEX::dolar)){// X, aussi comme a. Sommet de la pile
        if(X->vaut(a)){
          pile.pop_back();
          lu=pe.anaLex();
          a=lu.getLex();
        }
        else if(X->estTerminal())
          if(a==ULEX::dolar){
    	std::cerr<<"Fichier source inachevé"<<std::endl;
    	exit(1);
          }
          else{
    	std::cerr<<lu.getLexeme()<<" inattendu"<<std::endl;
    	lu=pe.anaLex();
    	a=lu.getLex();
          }
        switch(X->getSymbole()){
        case SYMBOLE::C:
          if(a==ULEX::a){
    	//inachevé
          }
        }
      }
    }
    et �a ne fait plus d'erreur, du moins, de compilation. Vu que X recopie le sommet de la pile, sans d�piler, ne suis-je pas oblig� d'utiliser shared_ptr?

    autre question, pourquoi "const" et "&" dans auto const & X=pile[pile.size() -1], (peut-�tre & � cause de pointeur?)

    une id�e?

  7. #7
    Expert �minent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 644
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activit� : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 644
    Par d�faut
    Salut,

    D�j�, dans le cadre pr�sent, tu n'as aucun int�r�t � travailler avec des std::shared_ptr, car le seul �l�ment qui puisse effectivement avoir un droit "de vie ou de mort" sur les diff�rents �l�ments serait la pile de ta classe.

    L'utilisation d'un std::unique_ptr serait donc largement plus int�ressante, ne serait-ce que pour �viter toute la gestion relative au comptage de r�f�rence qu'implique l'utilisation de std::shared_ptr.

    De plus, tu devrais prendre l'habitude de d�clarer tes variables au plus pr�s de leur premi�re utilisation, ce qui ferait que le constructeur prendrait une forme proche de
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::shared_ptr<terminal>E1=std::make_shared<terminal>();
      E1->setSymbole(SYMBOLE::dolar);
      pile.push_back(E1);
      std::shared_ptr<nonTerminal>E2=std::make_shared<nonTerminal>();
      E2->setSymbole(SYMBOLE::C);
      pile.push_back(E2);
      std::shared_ptr<synthese>E3=std::make_shared<synthese>();
      E3->setNomSynthese(typeSynthese::synthC);
      E3->ajoute("");
      E3->ajoute("");
      pile.push_back(E3);
    }
    En toutre, il serait sans doute utile de modifier le constructeur de tes classes pour �viter d'avoir � appeler ces mutateurs (setSymbole et setNomSynth�se) que je ne saurais voir, de mani�re � pouvoir utiliser un code qui serait d'avantage proche de
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::shared_ptr<terminal>E1=std::make_shared<terminal>(SYMBOLE::dolar);
      pile.push_back(E1);
      std::shared_ptr<nonTerminal>E2=std::make_shared<nonTerminal>(SYMBOLE::C);
      E2->setSymbole();
      pile.push_back(E2);
      std::shared_ptr<synthese>E3=std::make_shared<synthese>(typeSynthese::synthC);
      E3->ajoute("");
      E3->ajoute("");
      pile.push_back(E3);
    }
    au passage, as tu remarqu� que tu transmet une donn�e de type typeSynthese � une fonction nomm�e setNomSynthese

    Il y a quelque chose de "pas normal", parce que, dans la t�te de tout le monde, un nom n'est pas d'avantage un type que l'inverse. Or, une synth�se pourrait tr�s bien �tre d'un type particulier typeSynthese::synthC et avoir un nom qui lui est propre (ex: "mai-2020"), si tu estimes qu'il est possible, � un moment donn� de l'ex�cution, d'avoir deux synth�ses diff�rentes. Le nom deviendrait alors l'�l�ment qui te permettra de les diff�rencier (parce que l'autre, �galement de type typeSynthese::synthC porterait le nom de"avril-2020" par exemple).

    Et cela m'am�ne � une une autre remarque: il faut �tre coh�rent dans le choix noms (de type de donn�es, de donn�es et de fonctions):
    1. au niveau de la "casse" (la diff�rence minuscules / majuscules) en premier: tous les types doivent avoir la m�me casse. Pourquoi SYMBOL est-il en majuscule alors que typeSynthese est en camelCase
    2. Au niveau du nom utilis� ensuite: le nom (devrait) permet(tre) au lecteur de se faire une id�e pr�cise de l'usage auquel est destin� un �l�ment. Le meilleur moyen d'y arriver, c'est de choisir un nom qui soit effectivement en rapport avec cet usage.

    Citation Envoy� par Argagon (2006)
    Blissingr signifie le feu. C'est le feu.
    Le nom, c'est la chose
    Conna�t le nom, et tu ma�trise la chose
    Enfin, je doute tr�s fort que cette logique doive appara�tre au niveau du constructeur de ta classe, m�me si je comprend parfaitement que l'id�e soit d'avoir syst�matiquement ces trois �l�ments en d�but de pile. La raison de mon doute est cependant toute simple:

    Le principe m�me d'une pile est de r�cup�rer l'�l�ment qui se trouve "au sommet" de la pile, de le traiter, puis de le retirer; et ce, "tant qu'il y a un �l�ment" dans la pile.

    Les trois �l�ments (symbole dollar, symbole c, et syntheseC) vont donc ** forc�ment ** finir par �tre supprim� de la pile. Et la logique de travail de ta syntaxe devrait s'arr�ter.

    Par contre, ce n'est pas parce que tous les �l�ments de syntaxe ont �t� trait�s (et retir�s de la pile) que l'instance de ta classe syntaxe va ** forc�ment ** �tre d�truite. Apr�s tout, tu pourrais tr�s bien d�cider de r�utiliser cette instance pour traiter "un nouveau jeu de donn�es syntaxiques", ce qui sera sans doute "plus efficace" que de devoir commencer par d�truire l'instance existante pour ... le plaisir d'en cr�er une nouvelle.

    Et tu voudras tr�s certainement que ces trois �l�ments se retrouvent de nouveau au tout d�but de ta pile. Personnellement, j'aurais tendance � dire que cette logique devrait faire partie d'une fonction de ta classe (priv�e pour que l'utilisateur n'ait pas la possibilit� d'y faire appel "n'importe quand") qui pourrait �tre appel�e � chaque fois que l'on d�cide de commencer � traiter un nouveau "jeu syntaxique".

    Enfin, bref... Pour r�pondre � ta question: pourquoi
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    auto const & X=pile[pile.size() -1],
    :

    • auto parce que c'est plus facile que commencer � �crire le type pr�cis de l'�l�ment qui se trouve en pile (qui est de type std::shared_ptr<XXX>, m�me si je conseillerais de passer � un std::unique_ptr)
    • const parce que l'on ne veut surtout pas avoir la possibilit� de modifier l'�l�ment obtenu
    • & pour indiquer que l'on veut r�cup�rer une r�f�rence sur l'�l�ment qui se trouve dans la pile, ce qui permet d'�viter la copie (qui serait interdite avec un std::unique_ptr et qui, dans ton cas, n�cessiterait de mettre la logique de comptage de r�f�rence en branle)
    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

  8. #8
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    comme je disait
    Vu que X recopie le sommet de la pile, sans d�piler, ne suis-je pas oblig� d'utiliser shared_ptr?
    en modifiant pour opter pour unique_ptr, j'ai bien la m�thode ajoute(std::string). Pourquoi �a ne compile plus?
    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
     #include <memory>
    #include <iostream>
    #include "syntaxique.hpp"
    #include "enregistrements.hpp"
     
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::unique_ptr<enregistrement>E;
      E=std::make_unique<terminal>(SYMBOLE::dolar);
      //E->setSymbole(SYMBOLE::dolar);
      pile.push_back(std::move(E));
      E=std::make_unique<nonTerminal>(SYMBOLE::C);
      //E->setSymbole(SYMBOLE::C);
      pile.push_back(std::move(E));
      E=std::make_unique<synthese>(typeSynthese::synthC);
      //E->setNomSynthese(typeSynthese::synthC);
      E->ajoute("");
      E->ajoute("");
      E->setActionSemantique(1);
      pile.push_back(std::move(E));
    }
     
    void syntaxique::anaSynt(){
      uniLex lu;
      lu=pe.anaLex();
      a=lu.getLex();/*"a" est indiqué ainsi dans le dragonbook, 
    		  c'est l'unité lexicale lu par l'analyseur lexical*/
     
      pile.back();
      while( ! X->vaut(ULEX::dolar)){// X, aussi comme a. Sommet de la pile
        if(X->vaut(a)){
          pile.pop_back();
          lu=pe.anaLex();
          a=lu.getLex();
        }
        else if(X->estTerminal())
          if(a==ULEX::dolar){
    	std::cerr<<"Fichier source inachevé"<<std::endl;
    	exit(1);
          }
          else{
    	std::cerr<<lu.getLexeme()<<" inattendu"<<std::endl;
    	lu=pe.anaLex();
    	a=lu.getLex();
          }
        switch(X->quelType()){
        case type::TnonTerminal:
          if(X->getSymbole()==SYMBOLE::C)
    	if(a==ULEX::a){
    	  pile.pop_back();
    	  std::unique_ptr<synthese>temp=
    	    std::make_unique<synthese>(typeSynthese::synthA1);
    	  temp.ajoute("");
    	  temp.ajoute("");
    	  temp=std
    	}
        }
      }
    }
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    enregistrement.hpp
    class synthese:public enregistrement{
    void ajoute(std::string const &valAttr)override;
    };
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    $ g++ -c syntaxique.cpp
    syntaxique.cpp: In member function ‘void syntaxique::anaSynt()’:
    syntaxique.cpp:52:9: error: ‘class std::unique_ptr<synthese, std::default_delete<synthese> >’ has no member named ‘ajoute’
       52 |    temp.ajoute("");
          |         ^~~~~~
    syntaxique.cpp:53:9: error: ‘class std::unique_ptr<synthese, std::default_delete<synthese> >’ has no member named ‘ajoute’
       53 |    temp.ajoute("");
          |         ^~~~~~
    syntaxique.cpp:55:2: error: expected primary-expression before ‘}’ token
       55 |  }
          |  ^
    quelqu'un a une id�e?

  9. #9
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    �videment, il fallait faire:

  10. #10
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    j'ai ce syntaxique.cpp qui compile correctement, mais si je fait: le somment de pile sera-t-il encore "intact"?
    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
    #include <memory>
    #include <iostream>
    #include "syntaxique.hpp"
    #include "enregistrements.hpp"
     
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::unique_ptr<enregistrement>E;
      E=std::make_unique<terminal>(SYMBOLE::dolar);
      pile.push_back(std::move(E));
      E=std::make_unique<nonTerminal>(SYMBOLE::C);
      pile.push_back(std::move(E));
      E=std::make_unique<synthese>(typeSynthese::synthC);
      E->ajoute("");
      E->ajoute("");
      E->setActionSemantique(1);
      pile.push_back(std::move(E));
    }
     
    void syntaxique::anaSynt(){
      uniLex lu;
      std::unique_ptr<enregistrement>temp;
      lu=pe.anaLex();
      a=lu.getLex();/*"a" est indiqué ainsi dans le dragonbook, 
    		  c'est l'unité lexicale lu par l'analyseur lexical*/
     
      X=pile.back();
      while( ! X->vaut(ULEX::dolar)){// X, aussi comme a. Sommet de la pile
        if(X->vaut(a)){
          pile.pop_back();
          lu=pe.anaLex();
          a=lu.getLex();
        }
        else if(X->estTerminal())
          if(a==ULEX::dolar){
    	std::cerr<<"Fichier source inachevé"<<std::endl;
    	exit(1);
          }
          else{
    	std::cerr<<lu.getLexeme()<<" inattendu"<<std::endl;
    	lu=pe.anaLex();
    	a=lu.getLex();
          }
        switch(X->quelType()){
        case type::TnonTerminal:
          if(X->getSymbole()==SYMBOLE::C)
    	if(a==ULEX::a||a==ULEX::b){
    	  pile.pop_back();
    	  temp=std::make_unique<synthese>(typeSynthese::synthA1);
    	  temp->ajoute("");
    	  temp->ajoute("");
    	  pile.push_back(std::move(temp));
    	  temp=std::make_unique<nonTerminal>(SYMBOLE::A);
    	  pile.push_back(std::move(temp));
    	}
    	else if(a==ULEX::sep){
    	  std::cerr<<"le fichier commence par une virgule"<<std::endl;
    	  lu=pe.anaLex();
    	  a=lu.getLex();
    	}
    	else if(a==ULEX::dolar)
    	  pile.pop_back();
        }
        //inachevé
        X=std::move(pile.back());
      }
    }

  11. #11
    Expert confirm�
    Homme Profil pro
    Ing�nieur d�veloppement mat�riel �lectronique
    Inscrit en
    D�cembre 2015
    Messages
    1 599
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 62
    Localisation : France, Bouches du Rh�ne (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement mat�riel �lectronique
    Secteur : High Tech - �lectronique et micro-�lectronique

    Informations forums :
    Inscription : D�cembre 2015
    Messages : 1 599
    Par d�faut
    Bonjour,

    Si tu "move" un unique_ptr, tu le transf�res. Donc apr�s avoir effectu� X = std::move( pile.back() );, X est celui poss�de l'objet et le sommet de la pile aura un unique_ptr vid� de son �l�ment. Il faut alors ne pas oublier d'enlever cet unique_ptr du sommet.
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    X = std::move( pile.back() );
    if ( pile.back() )      // essayons de voir s'il reste quelque chose!
        std::cout << "ce message n'est pas affiché!";
    else
        pile.pop_back();    // ne pas conserver un pointeur vide dans la pile

  12. #12
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    la pile doit rester intact, j'utiliserais dons shared_ptr
    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
    #include <memory>
    #include <iostream>
    #include "syntaxique.hpp"
    #include "enregistrements.hpp"
     
    syntaxique::syntaxique(std::string const &nomFichier):pe(nomFichier){
      std::shared_ptr<enregistrement>E;
      E=std::make_shared<terminal>(SYMBOLE::dolar);
      pile.push_back(E);
      E=std::make_shared<nonTerminal>(SYMBOLE::C);
      pile.push_back(E);
      E=std::make_shared<synthese>(typeSynthese::synthC);
      E->ajoute("");
      E->ajoute("");
      E->setActionSemantique(1);
      pile.push_back(E);
    }
     
    void syntaxique::anaSynt(){
      uniLex lu;
      std::shared_ptr<enregistrement>temp;
      lu=pe.anaLex();
      a=lu.getLex();/*"a" est indiqué ainsi dans le dragonbook, 
    		  c'est l'unité lexicale lu par l'analyseur lexical*/
     
      X=pile.back();
      while( ! X->vaut(ULEX::dolar)){// X, aussi comme a. Sommet de la pile
        if(X->vaut(a)){
          pile.pop_back();
          lu=pe.anaLex();
          a=lu.getLex();
        }
        else if(X->estTerminal())
          if(a==ULEX::dolar){
    	std::cerr<<"Fichier source inachevé"<<std::endl;
    	exit(1);
          }
          else{
    	std::cerr<<lu.getLexeme()<<" inattendu"<<std::endl;
    	lu=pe.anaLex();
    	a=lu.getLex();
          }
        switch(X->quelType()){
        case type::TnonTerminal:
          if(X->getSymbole()==SYMBOLE::C)
    	if(a==ULEX::a||a==ULEX::b){
    	  pile.pop_back();
    	  temp=std::make_shared<synthese>(typeSynthese::synthA1);
    	  temp->ajoute("");
    	  temp->ajoute("");
    	  pile.push_back(temp);
    	  temp=std::make_shared<nonTerminal>(SYMBOLE::A);
    	  pile.push_back(temp);
    	}
    	else if(a==ULEX::sep){
    	  std::cerr<<"le fichier commence par une virgule"<<std::endl;
    	  lu=pe.anaLex();
    	  a=lu.getLex();
    	}
    	else if(a==ULEX::dolar)
    	  pile.pop_back();
        }
        //inachvé
        X=pile.back();
      }
    }
    le sujet du message est "enregistrement ne compile pas". Maintenant que tout compile bien, le probl�me est r�solu. Merci chalereux pour votre aide,

  13. #13
    R�dacteur/Mod�rateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 153
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 38
    Localisation : Canada

    Informations professionnelles :
    Activit� : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 153
    Billets dans le blog
    4
    Par d�faut
    Mauvaise r�ponse.
    Tu n'as aucunement besoin d'un shared_ptr ici.
    Un unique_ptr est la solution. Et pour utiliser sa valeur tu n'as pas besoin de le d�placer... tu peux utiliser get et r�cup�rer un pointeur.
    Pensez � consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation r�seau ?
    Aucune aide via MP ne sera dispens�e. Merci d'utiliser les forums pr�vus � cet effet.

  14. #14
    Invit�
    Invit�(e)
    Par d�faut
    En pr�tant une attention particuli�re � la dur�e de vie de l'objet. Un pile.pop_back() va d�truire l'unique_ptr et l'objet avec lui, et on se retrouvera avec des dangling r�f�rence / pointeur.

  15. #15
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    @winjerome. y aura-t-il aussi des dangling r�f�rence / pointeur avec shared_ptr?
    si oui, comment d�truire l'objet?

  16. #16
    Invit�
    Invit�(e)
    Par d�faut
    Oui et non.
    La r�f�rence sur le std::shared_ptr contenu dans la pile sera tout autant dangling.
    Par contre, si tu conserves comme tu le fais une copie X = pile.back();, alors X partagera la responsabilit� avec l'�l�ment dans la pile et continuera (seul) pass� le pile.pop_back();.

  17. #17
    Membre �clair�

    Homme Profil pro
    d�veloppeur � la maison
    Inscrit en
    Septembre 2006
    Messages
    414
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : d�veloppeur � la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 414
    Billets dans le blog
    16
    Par d�faut
    merci pour vos �claircissements

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. R�ponses: 1
    Dernier message: 31/07/2012, 18h53
  2. Le compilateur eclipse ne compile pas certaines classes
    Par kalysto dans le forum Eclipse Java
    R�ponses: 6
    Dernier message: 25/08/2007, 09h58
  3. les fichiers .class ne se compilent pas � la vol�?
    Par talbi404 dans le forum Eclipse Java
    R�ponses: 5
    Dernier message: 20/12/2006, 19h39
  4. [C# 2.0] Un exemple de classe g�n�rique qui ne compile pas.
    Par Pierre8r dans le forum Windows Forms
    R�ponses: 4
    Dernier message: 31/05/2006, 11h11
  5. [D�butant]Classe d'Authentification : compilation impossible
    Par acyclique dans le forum Servlets/JSP
    R�ponses: 4
    Dernier message: 23/08/2003, 19h42

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