Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: using a cla...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 25 Topic 45615 of 48417
Post > Topic >>

Re: using a class inside a class.

by Ian Collins <ian-news@[EMAIL PROTECTED] > Apr 29, 2008 at 09:50 AM

kwikius wrote:
> On Apr 28, 7:33 pm, "Jim Langston" <tazmas...@[EMAIL PROTECTED]
> wrote:
>
>> 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<CFoo> m_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<X> m_children;
};

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.
 




 25 Posts in Topic:
using a class inside a class.
phil.pellouchoud@[EMAIL P  2008-04-28 11:22:06 
Re: using a class inside a class.
"Jim Langston"   2008-04-28 11:33:55 
Re: using a class inside a class.
phil.pellouchoud@[EMAIL P  2008-04-28 14:03:43 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-29 09:08:35 
Re: using a class inside a class.
kwikius <andy@[EMAIL P  2008-04-28 14:41:37 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-29 09:50:53 
Re: using a class inside a class.
"kwikius" <a  2008-04-28 23:26:38 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-29 10:32:04 
Re: using a class inside a class.
"kwikius" <a  2008-04-28 23:47:15 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-29 11:07:51 
Re: using a class inside a class.
"Jim Langston"   2008-04-28 16:12:47 
Re: using a class inside a class.
"kwikius" <a  2008-04-29 01:01:47 
Re: using a class inside a class.
Kai-Uwe Bux <jkherciue  2008-04-29 06:03:21 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-29 01:38:46 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-29 20:57:30 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-29 01:46:56 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-29 05:00:50 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-29 05:07:21 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-30 08:13:53 
Re: using a class inside a class.
Cynic <nik.n.nair@[EMA  2008-04-29 07:45:16 
Re: using a class inside a class.
phil.pellouchoud@[EMAIL P  2008-04-29 09:09:48 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-30 02:07:51 
Re: using a class inside a class.
Ian Collins <ian-news@  2008-04-30 21:15:37 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-30 02:13:37 
Re: using a class inside a class.
James Kanze <james.kan  2008-04-30 02:19:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 13:07:08 CST 2008.