using a class inside a class.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phil.pellouchoud@gmail.com

    using a class inside a class.

    I did some searching online and i couldn't find anything in reference
    to this.

    I am using MinGW, gcc 4.3 and am having the following compilation
    issue:

    class CFoo
    {
    public:
    ...
    private:
    std::list<CFoom _children;
    };

    The complaint from the compiler looks like this:

    c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
    boost_concept_c heck.h: In instantiation of
    '__gnu_cxx::_SG IAssignableConc ept<CFoo>':
    c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
    stl_list.h:420: instantiated from 'std::list<CFoo ,
    std::allocator< CFoo'
    c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
    boost_concept_c heck.h:216: error:
    '__gnu_cxx::_SG IAssignableConc ept<_Tp>::__a' has incomplete type

    So, basically, I think what it's saying is that it doesn't know how to
    build the class because CFoo hasn't been defined by the time it's
    trying to create it (i.e. incomplete type). I tried adding
    "std::list<clas s CFoo>" as well, but that didn't work either. This
    compiles on visual studio with some warnings.

    I can make this work by making it "std::list<CFoo *>", but I'm
    wondering if there's a way to get this to work as defined.

    thanks for listening.

    -phil
  • Jim Langston

    #2
    Re: using a class inside a class.

    phil.pellouchou d@gmail.com wrote:
    I did some searching online and i couldn't find anything in reference
    to this.
    >
    I am using MinGW, gcc 4.3 and am having the following compilation
    issue:
    >
    class CFoo
    {
    public:
    ...
    private:
    std::list<CFoom _children;
    };
    >
    The complaint from the compiler looks like this:
    >
    c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
    boost_concept_c heck.h: In instantiation of
    '__gnu_cxx::_SG IAssignableConc ept<CFoo>':
    c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
    stl_list.h:420: instantiated from 'std::list<CFoo ,
    std::allocator< CFoo'
    c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
    boost_concept_c heck.h:216: error:
    '__gnu_cxx::_SG IAssignableConc ept<_Tp>::__a' has incomplete type
    >
    So, basically, I think what it's saying is that it doesn't know how to
    build the class because CFoo hasn't been defined by the time it's
    trying to create it (i.e. incomplete type). I tried adding
    "std::list<clas s CFoo>" as well, but that didn't work either. This
    compiles on visual studio with some warnings.
    >
    I can make this work by making it "std::list<CFoo *>", but I'm
    wondering if there's a way to get this to work as defined.
    >
    thanks for listening.
    All I can tell you is I've done this exact same thing in the past
    successfully in both Microsoft Visual C++ .net 2003 and DevC++. Here is
    something that compiles sucessfully in Microsoft Visual C++ .net 2003:

    #include <list>

    class CFoo
    {
    private:
    std::list<CFoom _children;
    };

    int main()
    {
    CFoo Foo;
    }

    No warnings, no errors.

    I don't know why your version of gcc is complaining, I don't think it
    should, AFAIK this is perfectly legal, although I haven't read the standard
    on it.

    --
    Jim Langston
    tazmaster@rocke tmail.com


    Comment

    • phil.pellouchoud@gmail.com

      #3
      Re: using a class inside a class.

      Here's exactly what i get when I try to compile that code:

      C:\>type foo.cpp
      #include <list>

      class CFoo
      {
      private:
      std::list<CFoom _children;

      };

      int main()
      {
      CFoo Foo;

      }
      C:\>gcc -v
      Using built-in specs.
      Target: i386-pc-mingw32
      Configured with: ../gcc-4.3.0/configure --prefix=/mingw --disable-nls
      --enable-languages=c,c++ ,fortran,objc,o bj-c++,ada,
      java --disable-win32-registry --disable-sjlj-exceptions --enable-
      libstdcxx-debug --enable-version-specific-runtime-libs
      --with-gmp=/mingw/src/gcc/gmp-mpfr-root --with-mpfr=/mingw/src/gcc/gmp-
      mpfr-root --enable-libgcj --enable-concept-checks
      --enable-shared
      Thread model: win32
      gcc version 4.3.0 (GCC)

      C:\>gcc -o foo foo.cpp
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h: In instantiation of '__gnu_cxx::_S
      GIAssignableCon cept<CFoo>':
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      stl_list.h:420: instantiated from 'std::list<CFoo , std:
      :allocator<CFoo '
      foo.cpp:6: instantiated from here
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:216: error: '__gnu_cxx::_SG IAssigna
      bleConcept<_Tp> ::__a' has incomplete type
      foo.cpp:4: error: forward declaration of 'class CFoo'
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h: In member function 'void __gnu_cxx
      ::_SGIAssignabl eConcept<_Tp>:: __constraints() [with _Tp = CFoo]':
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      stl_list.h:420: instantiated from 'std::list<CFoo , std:
      :allocator<CFoo '
      foo.cpp:6: instantiated from here
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:208: error: using invalid field '__
      gnu_cxx::_SGIAs signableConcept <_Tp>::__a'
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:209: error: using invalid field '__
      gnu_cxx::_SGIAs signableConcept <_Tp>::__a'
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:209: error: using invalid field '__
      gnu_cxx::_SGIAs signableConcept <_Tp>::__a'
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      stl_list.h:420: instantiated from 'std::list<CFoo , std:
      :allocator<CFoo '
      foo.cpp:6: instantiated from here
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:210: error: using invalid field '__
      gnu_cxx::_SGIAs signableConcept <_Tp>::__a'
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h: In member function 'void __gnu_cxx
      ::_SGIAssignabl eConcept<_Tp>:: __const_constra ints(const _Tp&) [with
      _Tp = CFoo]':
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:210: instantiated from 'void __gn
      u_cxx::_SGIAssi gnableConcept<_ Tp>::__constrai nts() [with _Tp = CFoo]'
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      stl_list.h:420: instantiated from 'std::list<CFoo , std:
      :allocator<CFoo '
      foo.cpp:6: instantiated from here
      c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
      boost_concept_c heck.h:214: error: using invalid field '__
      gnu_cxx::_SGIAs signableConcept <_Tp>::__a'

      C:\>

      Comment

      • Ian Collins

        #4
        Re: using a class inside a class.

        phil.pellouchou d@gmail.com wrote:
        Here's exactly what i get when I try to compile that code:
        >
        C:\>type foo.cpp
        #include <list>
        >
        class CFoo
        {
        private:
        std::list<CFoom _children;
        >
        };
        >
        int main()
        {
        CFoo Foo;
        >
        }
        >
        C:\>gcc -o foo foo.cpp
        c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
        boost_concept_c heck.h: In instantiation of '__gnu_cxx::_S
        GIAssignableCon cept<CFoo>':
        <snip>

        Looks like your compiler isn't configured correctly, try a gcc group.

        --
        Ian Collins.

        Comment

        • kwikius

          #5
          Re: using a class inside a class.

          On Apr 28, 7:33 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
          phil.pellouch.. .@gmail.com wrote:
          I did some searching online and i couldn't find anything in reference
          to this.
          >
          I am using MinGW, gcc 4.3 and am having the following compilation
          issue:
          >
          class CFoo
          {
          public:
             ...
          private:
             std::list<CFoom _children;
          };
          >
          The complaint from the compiler looks like this:
          >
          c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
          boost_concept_c heck.h: In instantiation of
          '__gnu_cxx::_SG IAssignableConc ept<CFoo>':
          c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
          stl_list.h:420:   instantiated from 'std::list<CFoo ,
          std::allocator< CFoo'
          c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
          boost_concept_c heck.h:216: error:
          '__gnu_cxx::_SG IAssignableConc ept<_Tp>::__a' has incomplete type
          >
          So, basically, I think what it's saying is that it doesn't know how to
          build the class because CFoo hasn't been defined by the time it's
          trying to create it (i.e. incomplete type).  I tried adding
          "std::list<clas s CFoo>" as well, but that didn't work either.  This
          compiles on visual studio with some warnings.
          >
          I can make this work by making it "std::list<CFoo *>", but I'm
          wondering if there's a way to get this to work as defined.
          >
          thanks for listening.
          >
          All I can tell you is I've done this exact same thing in the past
          successfully in both Microsoft Visual C++ .net 2003 and DevC++.  Here is
          something that compiles sucessfully in Microsoft Visual C++ .net 2003:
          >
          #include <list>
          >
          class CFoo
          {
          private:
              std::list<CFoom _children;
          >
          };
          >
          int main()
          {
              CFoo Foo;
          >
          }
          >
          No warnings, no errors.
          >
          I don't know why your version of gcc is complaining, I don't think it
          should, AFAIK this is perfectly legal, although I haven't read the standard
          on it.
          IMO gcc is correct. You could have a list of pointers or refs to CFoo
          but not recursive types. One workaround *may* be to use a typedef
          alias for CFoo. That may fool gcc, but I think its technically correct
          to call this an error.

          regards
          Andy Little

          Comment

          • Ian Collins

            #6
            Re: using a class inside a class.

            kwikius wrote:
            On Apr 28, 7:33 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
            >
            >All I can tell you is I've done this exact same thing in the past
            >successfully in both Microsoft Visual C++ .net 2003 and DevC++. Here is
            >something that compiles sucessfully in Microsoft Visual C++ .net 2003:
            >>
            >#include <list>
            >>
            >class CFoo
            >{
            >private:
            > std::list<CFoom _children;
            >>
            >};
            >>
            >int main()
            >{
            > CFoo Foo;
            >>
            >}
            >>
            >No warnings, no errors.
            >>
            >I don't know why your version of gcc is complaining, I don't think it
            >should, AFAIK this is perfectly legal, although I haven't read the standard
            >on it.
            >
            IMO gcc is correct. You could have a list of pointers or refs to CFoo
            but not recursive types. One workaround *may* be to use a typedef
            alias for CFoo. That may fool gcc, but I think its technically correct
            to call this an error.
            >
            Why? The class declares m_children to be a list of CFoo. It does not
            attempt to use any members of std::list that require a complete type.

            In effect, it's just like writing

            #include <list>

            class X;

            class CFoo
            {
            private:
            std::list<Xm_ch ildren;
            };

            class X {};

            int main()
            {
            CFoo Foo;
            }

            The complete class definition is not required until std::list's default
            constructor is instantiated in main().

            --
            Ian Collins.

            Comment

            • kwikius

              #7
              Re: using a class inside a class.


              "Ian Collins" <ian-news@hotmail.co mwrote in message
              news:67mv5uF2p7 o2gU7@mid.indiv idual.net...
              kwikius wrote:
              >On Apr 28, 7:33 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
              >>
              >>All I can tell you is I've done this exact same thing in the past
              >>successfull y in both Microsoft Visual C++ .net 2003 and DevC++. Here is
              >>something that compiles sucessfully in Microsoft Visual C++ .net 2003:
              >>>
              >>#include <list>
              >>>
              >>class CFoo
              >>{
              >>private:
              >> std::list<CFoom _children;
              >>>
              >>};
              >>>
              >>int main()
              >>{
              >> CFoo Foo;
              >>>
              >>}
              >>>
              >>No warnings, no errors.
              >>>
              >>I don't know why your version of gcc is complaining, I don't think it
              >>should, AFAIK this is perfectly legal, although I haven't read the
              >>standard
              >>on it.
              >>
              > IMO gcc is correct. You could have a list of pointers or refs to CFoo
              >but not recursive types. One workaround *may* be to use a typedef
              >alias for CFoo. That may fool gcc, but I think its technically correct
              >to call this an error.
              >>
              Why? The class declares m_children to be a list of CFoo. It does not
              attempt to use any members of std::list that require a complete type.
              Ah as to Why ... I Dunno. Hopefully someone of a more technical nature will
              help out as to why. From the error messages gcc is using C++0x style Concept
              checking.

              Various things to try to diagnose the problem. Try some other dummy template
              class than std::list.
              If that succeeds then std::list is concept checking and wont allow itself to
              be instantiated without a complete type or some such

              There is presumably an option to turn it off . ..

              regards
              Andy Little



              Comment

              • Ian Collins

                #8
                Re: using a class inside a class.

                kwikius wrote:
                "Ian Collins" <ian-news@hotmail.co mwrote:
                >>>
                >Why? The class declares m_children to be a list of CFoo. It does not
                >attempt to use any members of std::list that require a complete type.
                >
                Ah as to Why ... I Dunno. Hopefully someone of a more technical nature will
                help out as to why. From the error messages gcc is using C++0x style Concept
                checking.
                >
                It does, doesn't it? I thought that was a little odd, I didn't think
                gcc had built in boost libraries.

                --
                Ian Collins.

                Comment

                • kwikius

                  #9
                  Re: using a class inside a class.


                  "Ian Collins" <ian-news@hotmail.co mwrote in message
                  news:67n1j4F2p7 o2gU9@mid.indiv idual.net...
                  kwikius wrote:
                  >"Ian Collins" <ian-news@hotmail.co mwrote:
                  >>>>
                  >>Why? The class declares m_children to be a list of CFoo. It does not
                  >>attempt to use any members of std::list that require a complete type.
                  >>
                  >Ah as to Why ... I Dunno. Hopefully someone of a more technical nature
                  >will
                  >help out as to why. From the error messages gcc is using C++0x style
                  >Concept
                  >checking.
                  >>
                  It does, doesn't it? I thought that was a little odd, I didn't think
                  gcc had built in boost libraries.
                  Ahha yes its not C++0x Concepts, its old style concept checking . Theres
                  bound to be an option to turn that off.
                  Probbably a macro somewhere

                  Its all legit AFAIK.
                  After all std::list may want to for example instantiate some private
                  template type of allocate<sizeof (T)>
                  when its constructed for which it would obviously need the complete type.

                  regards
                  Andy Little



                  Comment

                  • Ian Collins

                    #10
                    Re: using a class inside a class.

                    kwikius wrote:
                    "Ian Collins" <ian-news@hotmail.co mwrote in message
                    news:67n1j4F2p7 o2gU9@mid.indiv idual.net...
                    >kwikius wrote:
                    >>"Ian Collins" <ian-news@hotmail.co mwrote:
                    >>>Why? The class declares m_children to be a list of CFoo. It does not
                    >>>attempt to use any members of std::list that require a complete type.
                    >>Ah as to Why ... I Dunno. Hopefully someone of a more technical nature
                    >>will
                    >>help out as to why. From the error messages gcc is using C++0x style
                    >>Concept
                    >>checking.
                    >>>
                    >It does, doesn't it? I thought that was a little odd, I didn't think
                    >gcc had built in boost libraries.
                    >
                    Ahha yes its not C++0x Concepts, its old style concept checking . Theres
                    bound to be an option to turn that off.
                    Probbably a macro somewhere
                    >
                    Its all legit AFAIK.
                    After all std::list may want to for example instantiate some private
                    template type of allocate<sizeof (T)>
                    when its constructed for which it would obviously need the complete type.
                    >
                    True, but that only happens when a CFoo is created and fully declared.

                    --
                    Ian Collins.

                    Comment

                    • Jim Langston

                      #11
                      Re: using a class inside a class.

                      Ian Collins wrote:
                      kwikius wrote:
                      >"Ian Collins" <ian-news@hotmail.co mwrote:
                      >>>>
                      >>Why? The class declares m_children to be a list of CFoo. It does
                      >>not attempt to use any members of std::list that require a complete
                      >>type.
                      >>
                      >Ah as to Why ... I Dunno. Hopefully someone of a more technical
                      >nature will help out as to why. From the error messages gcc is using
                      >C++0x style Concept checking.
                      >>
                      It does, doesn't it? I thought that was a little odd, I didn't think
                      gcc had built in boost libraries.
                      That had thrown me off also, the boost error messages on something that has
                      nothing to do with boost. I wonder if it's some compiler switch?

                      --
                      Jim Langston
                      tazmaster@rocke tmail.com


                      Comment

                      • kwikius

                        #12
                        Re: using a class inside a class.


                        "Jim Langston" <tazmaster@rock etmail.comwrote in message
                        news:9SsRj.2310 $fn.1310@newsfe 05.lga...
                        Ian Collins wrote:
                        >kwikius wrote:
                        >>"Ian Collins" <ian-news@hotmail.co mwrote:
                        >>>>>
                        >>>Why? The class declares m_children to be a list of CFoo. It does
                        >>>not attempt to use any members of std::list that require a complete
                        >>>type.
                        >>>
                        >>Ah as to Why ... I Dunno. Hopefully someone of a more technical
                        >>nature will help out as to why. From the error messages gcc is using
                        >>C++0x style Concept checking.
                        >>>
                        >It does, doesn't it? I thought that was a little odd, I didn't think
                        >gcc had built in boost libraries.
                        >
                        That had thrown me off also, the boost error messages on something that
                        has nothing to do with boost. I wonder if it's some compiler switch?
                        FWIW following gives something similar. The trick is to make some
                        dependency, which must be going on in the O.P.

                        #include <list>

                        template<typena me T>
                        struct dummy : T{ };

                        struct CFoo {
                        dummy<CFoomy_li st;
                        };

                        int main()
                        {
                        CFoo foo;
                        }



                        Comment

                        • James Kanze

                          #13
                          Re: using a class inside a class.

                          On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
                          phil.pellouch.. .@gmail.com wrote:
                          I did some searching online and i couldn't find anything in reference
                          to this.
                          I am using MinGW, gcc 4.3 and am having the following compilation
                          issue:
                          class CFoo
                          {
                          public:
                          ...
                          private:
                          std::list<CFoom _children;
                          };
                          The complaint from the compiler looks like this:
                          c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
                          boost_concept_c heck.h: In instantiation of
                          '__gnu_cxx::_SG IAssignableConc ept<CFoo>':
                          c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
                          stl_list.h:420: instantiated from 'std::list<CFoo ,
                          std::allocator< CFoo'
                          c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
                          boost_concept_c heck.h:216: error:
                          '__gnu_cxx::_SG IAssignableConc ept<_Tp>::__a' has incomplete type
                          So, basically, I think what it's saying is that it doesn't know how to
                          build the class because CFoo hasn't been defined by the time it's
                          trying to create it (i.e. incomplete type). I tried adding
                          "std::list<clas s CFoo>" as well, but that didn't work either. This
                          compiles on visual studio with some warnings.
                          I can make this work by making it "std::list<CFoo *>", but I'm
                          wondering if there's a way to get this to work as defined.
                          Nothing standards conformant.
                          All I can tell you is I've done this exact same thing in the past
                          successfully in both Microsoft Visual C++ .net 2003 and DevC++. Here is
                          something that compiles sucessfully in Microsoft Visual C++ .net 2003:
                          #include <list>
                          class CFoo
                          {
                          private:
                          std::list<CFoom _children;
                          };
                          int main()
                          {
                          CFoo Foo;
                          }
                          No warnings, no errors.
                          That's what's so nice about undefined behavior. The fact that
                          it works doesn't prove anything.
                          I don't know why your version of gcc is complaining, I don't
                          think it should, AFAIK this is perfectly legal, although I
                          haven't read the standard on it.
                          §17.4.3.6/2:

                          In particular, the effects are undefined in the
                          following cases:

                          [...]

                          -- if an incomplete type (3.9) is used as a template
                          argument when instantiating a template component.

                          A class is only a complete type after the closing braces, so
                          your code has undefined behavior. (The standard could have
                          allowed incomplete types for certain specific cases, but it
                          didn't.)

                          The current working draft still has basically the same words
                          (with an "unless specifically allowed" exception, for e.g.
                          shared_ptr). I believe, however, that it is the intent to
                          require an error here once concepts have been added to the
                          language.

                          G++ uses boost::concepts (or something derived from it, I'm
                          not sure) to generate errors in most of cases, rather than
                          letting the undefined behavior through.

                          --
                          James Kanze (GABI Software) email:james.kan ze@gmail.com
                          Conseils en informatique orientée objet/
                          Beratung in objektorientier ter Datenverarbeitu ng
                          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                          Comment

                          • James Kanze

                            #14
                            Re: using a class inside a class.

                            On Apr 29, 12:47 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
                            "Ian Collins" <ian-n...@hotmail.co mwrote in message
                            news:67n1j4F2p7 o2gU9@mid.indiv idual.net...
                            kwikius wrote:
                            "Ian Collins" <ian-n...@hotmail.co mwrote:
                            >Why? The class declares m_children to be a list of CFoo.
                            >It does not attempt to use any members of std::list that
                            >require a complete type.
                            Ah as to Why ... I Dunno. Hopefully someone of a more
                            technical nature will help out as to why. From the error
                            messages gcc is using C++0x style Concept checking.
                            It does, doesn't it? I thought that was a little odd, I
                            didn't think gcc had built in boost libraries.
                            Ahha yes its not C++0x Concepts, its old style concept
                            checking. Theres bound to be an option to turn that off.
                            Probbably a macro somewhere
                            It's off by default (but I always turn it on). To get it, you
                            need to define _GLIBCXX_CONCEP T_CHECKS, i.e. specify the option
                            -D_GLIBCXX_CONCE PT_CHECKS.
                            Its all legit AFAIK.
                            After all std::list may want to for example instantiate some private
                            template type of allocate<sizeof (T)>
                            when its constructed for which it would obviously need the complete type.
                            I don't think that there's any particular justification for this
                            particular class. The rule in C++-03 was general: only complete
                            types when instantiating a template, regardless. The committee
                            made no effort to second guess what implementors might or might
                            not want to do in specific cases.

                            As far as I know, there's also no movement to change this
                            particular rule (although some of the new classes, like
                            shared_ptr, are an explicit exception, and other rules have been
                            loosened---std::list will no longer require assignable, for
                            example).

                            --
                            James Kanze (GABI Software) email:james.kan ze@gmail.com
                            Conseils en informatique orientée objet/
                            Beratung in objektorientier ter Datenverarbeitu ng
                            9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                            Comment

                            • Ian Collins

                              #15
                              Re: using a class inside a class.

                              James Kanze wrote:
                              On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
                              >All I can tell you is I've done this exact same thing in the past
                              >successfully in both Microsoft Visual C++ .net 2003 and DevC++. Here is
                              >something that compiles sucessfully in Microsoft Visual C++ .net 2003:
                              >
                              >#include <list>
                              >
                              >class CFoo
                              >{
                              >private:
                              > std::list<CFoom _children;
                              >};
                              >
                              >int main()
                              >{
                              > CFoo Foo;
                              >}
                              >
                              >No warnings, no errors.
                              >
                              That's what's so nice about undefined behavior. The fact that
                              it works doesn't prove anything.
                              >
                              >I don't know why your version of gcc is complaining, I don't
                              >think it should, AFAIK this is perfectly legal, although I
                              >haven't read the standard on it.
                              >
                              §17.4.3.6/2:
                              >
                              In particular, the effects are undefined in the
                              following cases:
                              >
                              [...]
                              >
                              -- if an incomplete type (3.9) is used as a template
                              argument when instantiating a template component.
                              >
                              A class is only a complete type after the closing braces, so
                              your code has undefined behavior. (The standard could have
                              allowed incomplete types for certain specific cases, but it
                              didn't.)
                              >
                              But isn't the template component being instantiated in main after the
                              class is complete?

                              --
                              Ian Collins.

                              Comment

                              Working...