473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_check.h: In instantiation of
'__gnu_cxx::_SGIAssignableConcept<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_check.h:216: error:
'__gnu_cxx::_SGIAssignableConcept<_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<class 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
Jun 27 '08 #1
22 2757
ph**************@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_check.h: In instantiation of
'__gnu_cxx::_SGIAssignableConcept<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_check.h:216: error:
'__gnu_cxx::_SGIAssignableConcept<_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<class 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
ta*******@rocketmail.com
Jun 27 '08 #2
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,obj-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_check.h: In instantiation of '__gnu_cxx::_S
GIAssignableConcept<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_check.h:216: error: '__gnu_cxx::_SGIAssigna
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_check.h: In member function 'void __gnu_cxx
::_SGIAssignableConcept<_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_check.h:208: error: using invalid field '__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a'
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:209: error: using invalid field '__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a'
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:209: error: using invalid field '__
gnu_cxx::_SGIAssignableConcept<_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_check.h:210: error: using invalid field '__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a'
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In member function 'void __gnu_cxx
::_SGIAssignableConcept<_Tp>::__const_constraints( const _Tp&) [with
_Tp = CFoo]':
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:210: instantiated from 'void __gn
u_cxx::_SGIAssignableConcept<_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_check.h:214: error: using invalid field '__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a'

C:\>
Jun 27 '08 #3
ph**************@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_check.h: In instantiation of '__gnu_cxx::_S
GIAssignableConcept<CFoo>':
<snip>

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

--
Ian Collins.
Jun 27 '08 #4
On Apr 28, 7:33*pm, "Jim Langston" <tazmas...@rocketmail.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_check.h: In instantiation of
'__gnu_cxx::_SGIAssignableConcept<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_check.h:216: error:
'__gnu_cxx::_SGIAssignableConcept<_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<class 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

Jun 27 '08 #5
kwikius wrote:
On Apr 28, 7:33 pm, "Jim Langston" <tazmas...@rocketmail.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_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.
Jun 27 '08 #6

"Ian Collins" <ia******@hotmail.comwrote in message
news:67*************@mid.individual.net...
kwikius wrote:
>On Apr 28, 7:33 pm, "Jim Langston" <tazmas...@rocketmail.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.
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

Jun 27 '08 #7
kwikius wrote:
"Ian Collins" <ia******@hotmail.comwrote:
>>>
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.
Jun 27 '08 #8

"Ian Collins" <ia******@hotmail.comwrote in message
news:67*************@mid.individual.net...
kwikius wrote:
>"Ian Collins" <ia******@hotmail.comwrote:
>>>>
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

Jun 27 '08 #9
kwikius wrote:
"Ian Collins" <ia******@hotmail.comwrote in message
news:67*************@mid.individual.net...
>kwikius wrote:
>>"Ian Collins" <ia******@hotmail.comwrote:
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.
Jun 27 '08 #10
Ian Collins wrote:
kwikius wrote:
>"Ian Collins" <ia******@hotmail.comwrote:
>>>>
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
ta*******@rocketmail.com
Jun 27 '08 #11

"Jim Langston" <ta*******@rocketmail.comwrote in message
news:9S****************@newsfe05.lga...
Ian Collins wrote:
>kwikius wrote:
>>"Ian Collins" <ia******@hotmail.comwrote:
>
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<typename T>
struct dummy : T{ };

struct CFoo {
dummy<CFoomy_list;
};

int main()
{
CFoo foo;
}

Jun 27 '08 #12
On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rocketmail.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_check.h: In instantiation of
'__gnu_cxx::_SGIAssignableConcept<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_check.h:216: error:
'__gnu_cxx::_SGIAssignableConcept<_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<class 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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #13
On Apr 29, 12:47 am, "kwikius" <a...@servocomm.freeserve.co.ukwrote:
"Ian Collins" <ian-n...@hotmail.comwrote in message
news:67*************@mid.individual.net...
kwikius wrote:
"Ian Collins" <ian-n...@hotmail.comwrote:
>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_CONCEPT_CHECKS, i.e. specify the option
-D_GLIBCXX_CONCEPT_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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #14
James Kanze wrote:
On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rocketmail.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.
Jun 27 '08 #15
Jim Langston wrote:
Ian Collins wrote:
>kwikius wrote:
>>"Ian Collins" <ia******@hotmail.comwrote:
>
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.
With regard to std::list, no particular reason. The standard just requires
all types to be complete when used with the STL components. The committee
just did not include an exception for std::list, even though any straight
forward implementation of std::list that does not do something overly smart
or funny will work gracefully with incomplete types. (I consider it a
defect in the standard, but I think that is just me: the drafts for C++0X
have the same language.)

>>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?
[OT] Nope. It depends on how g++ and in particular the STL that ships with
it are built on your machine. If you make it with --enable-concept-checks,
you get those errors. If you disable concept-checks, std::list will behave
nicely with regard to incomplete types (although that is not guaranteed by
the standard nor by the g++ folks).
Best

Kai-Uwe Bux
Jun 27 '08 #16
On Apr 29, 10:57 am, Ian Collins <ian-n...@hotmail.comwrote:
James Kanze wrote:
On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rocketmail.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?
The class itself will be instantiated anytime it is used in a
context where a complete type is required. (How could it be
otherwise?) Class members (functions, static data members) will
be instantiated when (and only when) they are used. Since only
complete types can be used as member variables, the class itself
must be instantiated in CFoo. (Note that declaring the type as
"std::list< CFoo >* m_children" should work.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #17
On Apr 29, 5:00 pm, James Kanze <james.ka...@gmail.comwrote:
On Apr 29, 10:57 am, Ian Collins <ian-n...@hotmail.comwrote:
James Kanze wrote:
On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rocketmail.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++. Hereis
>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?

The class itself will be instantiated anytime it is used in a
context where a complete type is required. (How could it be
otherwise?) Class members (functions, static data members) will
be instantiated when (and only when) they are used. Since only
complete types can be used as member variables, the class itself
must be instantiated in CFoo. (Note that declaring the type as
"std::list< CFoo >* m_children" should work.)

--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
>(Note that declaring the type as
"std::list< CFoo >* m_children" should work.)
this would create a pointer to a LIST?
and would it help then if the std::list is created outside the
class?
Jun 27 '08 #18
On Apr 29, 1:46 am, James Kanze <james.ka...@gmail.comwrote:
On Apr 29, 12:47 am, "kwikius" <a...@servocomm.freeserve.co.ukwrote:
"Ian Collins" <ian-n...@hotmail.comwrote in message
news:67*************@mid.individual.net...
kwikius wrote:
>"Ian Collins" <ian-n...@hotmail.comwrote:
>>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_CONCEPT_CHECKS, i.e. specify the option
-D_GLIBCXX_CONCEPT_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.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
did the default behavior change in gcc 4.3? i seem to get it by
default; and I don't know how to turn it off. I did try doing a
#undefine _GLIBCXX_CONCEPT_CHECKS

at the top of the sample app:

---- cut here ----
#undef _GLIBCXX_CONCEPT_CHECKS

#include <list>

class CFoo
{
private:
std::list<CFoom_children;

};

int main()
{
CFoo Foo;
}
---- cut here ----

But i still get the same error. I would love to be able to simply
disable it if I could...

-phil
Jun 27 '08 #19
On Apr 29, 10:13 pm, Ian Collins <ian-n...@hotmail.comwrote:

[...]
It's not uncommon for classes to have std::auto_ptr members
which use incomplete types.
It's undefined behavior, so there will be no such cases in
correct code. (Strangely enough, however, g++ doesn't seem to
cover this case in its concept checking. And of course,
typically, there won't be any reason for it not to work, at
least on machines where all object pointers have the same size
and representation.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #20
On Apr 29, 6:09 pm, phil.pellouch...@gmail.com wrote:
On Apr 29, 1:46 am, James Kanze <james.ka...@gmail.comwrote:
[...]
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_CONCEPT_CHECKS, i.e. specify the option
-D_GLIBCXX_CONCEPT_CHECKS.
[...]
did the default behavior change in gcc 4.3?
I don't know. The latest version I currently have installed
here is 4.1.0. (I really should install 4.3, but I haven't had
time as yet.)

I know that the g++ people are implementing a preliminary
version of concepts, which will change the way this is handled.
i seem to get it by default; and I don't know how to turn it
off. I did try doing a
#undefine _GLIBCXX_CONCEPT_CHECKS
at the top of the sample app:
---- cut here ----
#undef _GLIBCXX_CONCEPT_CHECKS
#include <list>
class CFoo
{
private:
std::list<CFoom_children;
};
int main()
{
CFoo Foo;
}
---- cut here ----
But i still get the same error. I would love to be able to
simply disable it if I could...
Just compile with an older version of g++. But why? It will be
a required error in the future, so you won't be able to upgrade
compilers, or us any other more recent compiler, if you do so.
The code is illegal today; it just happens to work with some
compilers, by chance, but even then, the compiler vendor doesn't
guarantee it.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #21
James Kanze wrote:
On Apr 29, 10:13 pm, Ian Collins <ian-n...@hotmail.comwrote:

[...]
>It's not uncommon for classes to have std::auto_ptr members
which use incomplete types.

It's undefined behavior, so there will be no such cases in
correct code. (Strangely enough, however, g++ doesn't seem to
cover this case in its concept checking. And of course,
typically, there won't be any reason for it not to work, at
least on machines where all object pointers have the same size
and representation.)
That's the bit I don't get - the compiler can't compile the class if the
size of a member is unknown, so why should this be undefined behaviour?
Implementation defined maybe, but undefined?

--
Ian Collins.
Jun 27 '08 #22
On Apr 29, 4:45 pm, Cynic <nik.n.n...@gmail.comwrote:
On Apr 29, 5:00 pm, James Kanze <james.ka...@gmail.comwrote:
On Apr 29, 10:57 am, Ian Collins <ian-n...@hotmail.comwrote:
James Kanze wrote:
On Apr 28, 8:33 pm, "Jim Langston" <tazmas...@rocketmail.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?
The class itself will be instantiated anytime it is used in
a context where a complete type is required. (How could it
be otherwise?) Class members (functions, static data
members) will be instantiated when (and only when) they are
used. Since only complete types can be used as member
variables, the class itself must be instantiated in CFoo.
(Note that declaring the type as "std::list< CFoo >*
m_children" should work.)
this would create a pointer to a LIST?
Yes. And since declaring a pointer to the type doesn't require
the type (i.e. the instantiation of std::list) to be complete,
it doesn't trigger instantiation of the template.
and would it help then if the std::list is created outside the
class?
Yes. As long as the type in question is complete whenever the
class is instantiated. The formal rules as to when something is
intantiated are fairly complex, but a rough approximation,
sufficient for most concerns, is simply that the class itself
will be instantiated anytime the compiler needs a complete type,
or something in the class, and the class members will be
instantiated anytime they are used.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
1
by: Bryan Parkoff | last post by:
I know how to write "Pointer to Function" inside struct or class without using static, but I have decided to add static to all functions inside struct or class because I want member functions to be...
3
by: Pranav Shah | last post by:
What is the differrence between using the "using" caluse outside of the namespace definition and inside the namespace. Example Outside: using System; namespace Example.Outside { }
3
by: AK | last post by:
I'm using a .NET Windows Forms Applications project. I'm using LoadLibrary & GetProcAddress to use a DLL function. This is all done in the main cpp file. I would like to use this DLL function in a...
2
by: | last post by:
Today I learned that creating cookies inside of a custom class in ASP.NET 2.0 requires that you prefix it with HttpContext.Current..., e.g. : ...
10
by: Luke | last post by:
Hi. I am trying to make correct layout, here is an example of (dynamically generated content via jsp): http://localhost/www/layout.htm Most outer div is positioned absolute (if not then it...
5
by: Lambuz | last post by:
First of all, is it possible usign .NET remoting feature inside a .NET applet loaded into a tag object inside an HTML page ? <OBJECT id="myID" height="150" width="300"...
65
by: Arjen | last post by:
Hi, Form a performance perspective, is it wise to use the ref statement as much as possible? Thanks! Arjen
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.