By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

class definition recursion?

P: n/a
I am having trouble getting a piece of code to compile on VC++ 6.0...
Compiles fine on MAC OS X under X-Code....
#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;

};
I tried putting class myClass; in front of the class definition but it
didn't help...

errors...
C:\program files\microsoft visual studio\vc98\include\list(29) : error
C2079: '_Value' uses undefined class 'myClass'
C:\Documents and Settings\username\Desktop\deleteme
\deleteme.cpp(15) : see reference to class template instantiation
'std::list<class myClass,class std::allocator<class myClass' being
compiled
c:\program files\microsoft visual studio\vc98\include
\functional(185) : error C2079: 'value' uses undefined class 'myClass'
c:\program files\microsoft visual studio\vc98\include
\list(285) : see reference to class template instantiation
'std::binder2nd<struct std::not_equal_to<class myClass' being
compiled
C:\Documents and Settings\user\Desktop\deleteme
\deleteme.cpp(15) : see reference to class template instantiation
'std::list<class myClass,class std::allocator<class myClass' being
compiled

Jun 14 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On 2007-06-14 17:48, SpreadTooThin wrote:
I am having trouble getting a piece of code to compile on VC++ 6.0...
Compiles fine on MAC OS X under X-Code....
#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;

};
I tried putting class myClass; in front of the class definition but it
didn't help...
Except for having forgotten to include <stringit looks fine to me. Any
special reason for using VC++ 6, if not go and get VC++2005 Express and
it will work.

--
Erik Wikström
Jun 14 '07 #2

P: n/a
On Jun 14, 8:48 am, SpreadTooThin <bjobrie...@gmail.comwrote:
I am having trouble getting a piece of code to compile on VC++ 6.0...
Compiles fine on MAC OS X under X-Code....

#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;

};

I tried putting class myClass; in front of the class definition but it
didn't help...

errors...
C:\program files\microsoft visual studio\vc98\include\list(29) : error
C2079: '_Value' uses undefined class 'myClass'
C:\Documents and Settings\username\Desktop\deleteme
\deleteme.cpp(15) : see reference to class template instantiation
'std::list<class myClass,class std::allocator<class myClass' being
compiled
c:\program files\microsoft visual studio\vc98\include
\functional(185) : error C2079: 'value' uses undefined class 'myClass'
c:\program files\microsoft visual studio\vc98\include
\list(285) : see reference to class template instantiation
'std::binder2nd<struct std::not_equal_to<class myClass' being
compiled
C:\Documents and Settings\user\Desktop\deleteme
\deleteme.cpp(15) : see reference to class template instantiation
'std::list<class myClass,class std::allocator<class myClass' being
compiled
Works for me. I am using Visual C++ 2005 Express Edition though.

Jun 14 '07 #3

P: n/a
On Jun 14, 10:40 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-06-14 17:48, SpreadTooThin wrote:
I am having trouble getting a piece of code to compile on VC++ 6.0...
Compiles fine on MAC OS X under X-Code....
#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;
};
I tried putting class myClass; in front of the class definition but it
didn't help...

Except for having forgotten to include <stringit looks fine to me. Any
special reason for using VC++ 6, if not go and get VC++2005 Express and
it will work.

--
Erik Wikström
Yes your right i forgot to include <stringin the posting here.. but
not in the code.
Well I'm trying to write cross platform code.. for windows and mac os
x...
All I have for development on windozs is Visual C++ 6.0

Just curious but the application I tried to make was a win32 console
application...

Jun 14 '07 #4

P: n/a
SpreadTooThin wrote:
>
#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;

};
At the point where myClass::objects is declared, the type myClass is
incomplete (it's not complete until the closing curly brace). The
behavior of a program that uses an incomplete type as a template
argument is undefined (in most cases, including this one). So an
implementation is not required to accept this code or to do anything
sensible with it.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Jun 14 '07 #5

P: n/a
On 14 Jun, 17:58, SpreadTooThin <bjobrie...@gmail.comwrote:
On Jun 14, 10:40 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-06-14 17:48, SpreadTooThin wrote:
I am having trouble getting a piece of code to compile
<snip code>
Except for having forgotten to include <stringit looks fine to me.
Yes your right i forgot to include <stringin the posting here.. but
not in the code.
That sort of mistake should never happen, and ensuring it doesn't is
trivial. If you are going to post code in a message, you should copy
and paste *directly* from your code editor into your message, as per
FAQ 5.8. Whatever you did instead - maybe you copied and pasted
separate snippets (bad), maybe you typed code directly into your post
(very bad) - you managed to leave a line out. In this case it was
obvious what you had omitted and it didn't affect things. Next time,
the bit you accidentally fail to post could be absolutely crucial to
understanding your problem and providing the answer. If that happens,
you might find you get little or no help, or, worse, you and the
people trying to help you could end up on a wild goose chase because
of the misunderstanding.
Well I'm trying to write cross platform code.. for windows and mac os
x...
All I have for development on windozs is Visual C++ 6.0
That compiler is archaic. As Erik Wikström said, get Visual C++ 2005
Express. It's free to download so there's nothing stopping you getting
up to date.

Gavin Deane

Jun 14 '07 #6

P: n/a
On 14 Jun, 18:08, Pete Becker <p...@versatilecoding.comwrote:
SpreadTooThin wrote:
#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;
};

At the point where myClass::objects is declared, the type myClass is
incomplete (it's not complete until the closing curly brace). The
behavior of a program that uses an incomplete type as a template
argument is undefined (in most cases, including this one). So an
implementation is not required to accept this code or to do anything
sensible with it.
I thought there was a rule about not using incomplete types as
template arguments, but Comeau online compiled the OP's code with no
problem. That's not inconsistent with undefined behaviour, but the
only thing I can find in the standard (1998 version) is a note in
14.3.1/2 that says "a template type argument may be an incomplete
type". Have I missed something?

Gavin Deane

Jun 14 '07 #7

P: n/a
Gavin Deane wrote:
On 14 Jun, 18:08, Pete Becker <p...@versatilecoding.comwrote:
>SpreadTooThin wrote:
>>#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;
};
At the point where myClass::objects is declared, the type myClass is
incomplete (it's not complete until the closing curly brace). The
behavior of a program that uses an incomplete type as a template
argument is undefined (in most cases, including this one). So an
implementation is not required to accept this code or to do anything
sensible with it.

I thought there was a rule about not using incomplete types as
template arguments, but Comeau online compiled the OP's code with no
problem. That's not inconsistent with undefined behaviour, but the
only thing I can find in the standard (1998 version) is a note in
14.3.1/2 that says "a template type argument may be an incomplete
type". Have I missed something?

Gavin Deane
I think the problem here is that the OP is creating an object of the
template instance type as part of the type in the template's argument.
This instance cannot be constructed...or at least the standard doesn't
say what happens apparently.

If the OP were to use a pointer here I /think/ they would be ok. They
would need to create the object in an area of code where "myClass" was
fully defined.
Jun 14 '07 #8

P: n/a
Gavin Deane wrote:
On 14 Jun, 18:08, Pete Becker <p...@versatilecoding.comwrote:
>SpreadTooThin wrote:
>>#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;
};
At the point where myClass::objects is declared, the type myClass is
incomplete (it's not complete until the closing curly brace). The
behavior of a program that uses an incomplete type as a template
argument is undefined (in most cases, including this one). So an
implementation is not required to accept this code or to do anything
sensible with it.

I thought there was a rule about not using incomplete types as
template arguments, but Comeau online compiled the OP's code with no
problem. That's not inconsistent with undefined behaviour, but the
only thing I can find in the standard (1998 version) is a note in
14.3.1/2 that says "a template type argument may be an incomplete
type". Have I missed something?
No, I missed a bit of precision: what I said about myClass above applies
to standard library components, not to templates in general.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Jun 14 '07 #9

P: n/a
Pete Becker wrote:
Gavin Deane wrote:
>On 14 Jun, 18:08, Pete Becker <p...@versatilecoding.comwrote:
>>SpreadTooThin wrote:

#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;
};
At the point where myClass::objects is declared, the type myClass is
incomplete (it's not complete until the closing curly brace). The
behavior of a program that uses an incomplete type as a template
argument is undefined (in most cases, including this one). So an
implementation is not required to accept this code or to do anything
sensible with it.

I thought there was a rule about not using incomplete types as
template arguments, but Comeau online compiled the OP's code with no
problem. That's not inconsistent with undefined behaviour, but the
only thing I can find in the standard (1998 version) is a note in
14.3.1/2 that says "a template type argument may be an incomplete
type". Have I missed something?

No, I missed a bit of precision: what I said about myClass above applies
to standard library components, not to templates in general.
Sorry, hit Send too soon. The behavior is undefined, which means that
there are no constraints imposed by the standard on what the
implementation does. Once thing it can do is compile the code in the way
you'd expect. But even if it does compile in this simple form, I'm
betting it won't if you add inline functions, defined in the class body,
that do things to myClass::objects that require knowing something about
myClass.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Jun 14 '07 #10

P: n/a
On 14 Jun, 20:59, Pete Becker <p...@versatilecoding.comwrote:
Pete Becker wrote:
Gavin Deane wrote:
I thought there was a rule about not using incomplete types as
template arguments, but Comeau online compiled the OP's code with no
problem. That's not inconsistent with undefined behaviour, but the
only thing I can find in the standard (1998 version) is a note in
14.3.1/2 that says "a template type argument may be an incomplete
type". Have I missed something?
No, I missed a bit of precision: what I said about myClass above applies
to standard library components, not to templates in general.

Sorry, hit Send too soon. The behavior is undefined, which means that
there are no constraints imposed by the standard on what the
implementation does. Once thing it can do is compile the code in the way
you'd expect. But even if it does compile in this simple form, I'm
betting it won't if you add inline functions, defined in the class body,
that do things to myClass::objects that require knowing something about
myClass.
Thanks. In practice I couldn't work out what code like you suggest
could logically do so undefined behaviour isn't a surprise, but I'd
been trying to find the rule in the templates section of the standard.
Now you've told me where to look, I've found it. If anyone wants the
chapter and verse, it's 17.4.3.6/2.

Gavin Deane

Jun 14 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.