dimanche 3 avril 2016

Am I forced to use 2 headers or what is the way using one

        class session_elem;
        typedef std::map<std::string, session_elem> autosession;
        union session_elem_t{
            std::string s;
            int64_t n;
            char c;
            std::function<void(autosession*)> f;
            autosession r;
        };
        class session_elem{
            enum type{s,n,c,f,r};
            session_elem_t val;
        };
        typedef std::map<std::string, session_elem> autosession;

Is there a solution out of this puzzle ?

Depending on the order, I get a forward declaration error.

What order of declaration must I use for my code to compile under GCC 5.3 ?

error given is

/bin/sh -c '/usr/bin/make -j8 -e -f  Makefile'
----------Building project:[ ArchiUtils - Debug ]----------
make[1]: Entering directory '/home/archivist/Projets/zdd/ArchiUtils/ArchiUtils'
codelite-cc /usr/bin/g++  -c  "/home/archivist/Projets/zdd/ArchiUtils/ArchiUtils/main.cpp" -pedantic -std=c++14 -Wall -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I.
In file included from /usr/include/c++/5.3.1/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/5.3.1/bits/char_traits.h:39,
                 from /usr/include/c++/5.3.1/ios:40,
                 from /usr/include/c++/5.3.1/ostream:38,
                 from /usr/include/c++/5.3.1/iostream:39,
                 from /home/archivist/Projets/zdd/ArchiUtils/ArchiUtils/main.cpp:1:
/usr/include/c++/5.3.1/bits/stl_pair.h: In instantiation of 'struct std::pair<const std::__cxx11::basic_string<char>, ArchiUtils::v1::sv0::session_elem>':
/usr/include/c++/5.3.1/functional:1981:45:   required by substitution of 'template<class _Functor, class> std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = std::function<void(std::map<std::__cxx11::basic_string<char>, ArchiUtils::v1::sv0::session_elem>*)>; <template-parameter-1-2> = <missing>]'
/home/archivist/Projets/zdd/ArchiUtils/ArchiUtils/ArchiUtils.hpp:1003:10:   required from here
/usr/include/c++/5.3.1/bits/stl_pair.h:102:11: error: 'std::pair<_T1, _T2>::second' has incomplete type
       _T2 second;                /// @c second is a copy of the second object
           ^
In file included from /home/archivist/Projets/zdd/ArchiUtils/ArchiUtils/main.cpp:2:0:
/home/archivist/Projets/zdd/ArchiUtils/ArchiUtils/ArchiUtils.hpp:1003:10: note: forward declaration of 'class ArchiUtils::v1::sv0::session_elem'
    class session_elem{
          ^
ArchiUtils.mk:95: recipe for target 'Debug/main.cpp.o' failed
make[1]: *** [Debug/main.cpp.o] Error 1
make[1]: Leaving directory '/home/archivist/Projets/zdd/ArchiUtils/ArchiUtils'
Makefile:4: recipe for target 'All' failed
make: *** [All] Error 2
====4 errors, 3 warnings====

Aucun commentaire:

Enregistrer un commentaire