473,698 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jun 27 '08
22 2796
kwikius wrote:
"Ian Collins" <ia******@hotma il.comwrote in message
news:67******** *****@mid.indiv idual.net...
>kwikius wrote:
>>"Ian Collins" <ia******@hotma il.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 #11
Ian Collins wrote:
kwikius wrote:
>"Ian Collins" <ia******@hotma il.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*******@rocke tmail.com
Jun 27 '08 #12
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:ja******* **@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
Jun 27 '08 #13
On Apr 29, 12:47 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
"Ian Collins" <ian-n...@hotmail.co mwrote in message
news:67******** *****@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:ja******* **@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
Jun 27 '08 #14
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.
Jun 27 '08 #15
Jim Langston wrote:
Ian Collins wrote:
>kwikius wrote:
>>"Ian Collins" <ia******@hotma il.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.co mwrote:
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?
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 objektorientier ter Datenverarbeitu ng
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...@gm ail.comwrote:
On Apr 29, 10:57 am, Ian Collins <ian-n...@hotmail.co mwrote:
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++. 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 objektorientier ter Datenverarbeitu ng
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...@gm ail.comwrote:
On Apr 29, 12:47 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
"Ian Collins" <ian-n...@hotmail.co mwrote in message
news:67******** *****@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.ka. ..@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
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_CONCEP T_CHECKS

at the top of the sample app:

---- cut here ----
#undef _GLIBCXX_CONCEP T_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.co mwrote:

[...]
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 objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #20

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

Similar topics

12
10030
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 class and a function in Python ??? Consider the following code fragments : # Fragment 1 begins a = 1
28
20327
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()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
1
3976
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 bound inside struct or class to become global functions. It makes easier for me to use "struct.memberfunction()" instead of "globalfunction()" when I have to use dot between struct and member function rather than global function. I do not have...
3
1912
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
1896
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 .h file. So I code : (Proc2) (0x378, 12)....... (where Proc2 is the function) I get a compiler error : C2065 : 'Proc2' : undeclared identifier. I'm guessing I'm not calling this function properly - how can I fix this problem ? When I write a...
2
2141
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. : HttpContext.Current.Response.Cookies.Add("myNewCookie"); I am wondering if there are any landmines that I should know about, or if this will work pretty much as I am expecting a cookie should.
10
9199
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 will not grow when content inside div.body is greater than width of window of user agent), anyway anyone knowlegable can see it in sources...
5
3598
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" classid="http:applet.dll#test.applet"</OBJECT> If not please can anyone explain why ? I think yes and so I'd written a small example immediately I've met a problem.
65
3901
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
2968
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 reason you would want to do this is for example to trigger something from an OnPaint event without resorting to boolean switches-- say if a user presses the "M" key while the program is Painting, the user gets the PaintHandler to do something else. ...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.