473,800 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class definition recursion?

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<myCla ssobjects;

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

errors...
C:\program files\microsoft visual studio\vc98\inc lude\list(29) : error
C2079: '_Value' uses undefined class 'myClass'
C:\Documents and Settings\userna me\Desktop\dele teme
\deleteme.cpp(1 5) : see reference to class template instantiation
'std::list<clas s myClass,class std::allocator< class myClass' being
compiled
c:\program files\microsoft visual studio\vc98\inc lude
\functional(185 ) : error C2079: 'value' uses undefined class 'myClass'
c:\program files\microsoft visual studio\vc98\inc lude
\list(285) : see reference to class template instantiation
'std::binder2nd <struct std::not_equal_ to<class myClass' being
compiled
C:\Documents and Settings\user\D esktop\deleteme
\deleteme.cpp(1 5) : see reference to class template instantiation
'std::list<clas s myClass,class std::allocator< class myClass' being
compiled

Jun 14 '07 #1
10 6445
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<myCla ssobjects;

};
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
On Jun 14, 8:48 am, SpreadTooThin <bjobrie...@gma il.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<myCla ssobjects;

};

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

errors...
C:\program files\microsoft visual studio\vc98\inc lude\list(29) : error
C2079: '_Value' uses undefined class 'myClass'
C:\Documents and Settings\userna me\Desktop\dele teme
\deleteme.cpp(1 5) : see reference to class template instantiation
'std::list<clas s myClass,class std::allocator< class myClass' being
compiled
c:\program files\microsoft visual studio\vc98\inc lude
\functional(185 ) : error C2079: 'value' uses undefined class 'myClass'
c:\program files\microsoft visual studio\vc98\inc lude
\list(285) : see reference to class template instantiation
'std::binder2nd <struct std::not_equal_ to<class myClass' being
compiled
C:\Documents and Settings\user\D esktop\deleteme
\deleteme.cpp(1 5) : see reference to class template instantiation
'std::list<clas s myClass,class std::allocator< class myClass' being
compiled
Works for me. I am using Visual C++ 2005 Express Edition though.

Jun 14 '07 #3
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<myCla ssobjects;
};
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
SpreadTooThin wrote:
>
#include <list>
class myClass
{
private:
std::string name;
std::list<myCla ssobjects;

};
At the point where myClass::object s 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
On 14 Jun, 17:58, SpreadTooThin <bjobrie...@gma il.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 misunderstandin g.
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
On 14 Jun, 18:08, Pete Becker <p...@versatile coding.comwrote :
SpreadTooThin wrote:
#include <list>
class myClass
{
private:
std::string name;
std::list<myCla ssobjects;
};

At the point where myClass::object s 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
Gavin Deane wrote:
On 14 Jun, 18:08, Pete Becker <p...@versatile coding.comwrote :
>SpreadTooThi n wrote:
>>#include <list>
class myClass
{
private:
std::string name;
std::list<myCla ssobjects;
};
At the point where myClass::object s 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
implementati on 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...o r 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
Gavin Deane wrote:
On 14 Jun, 18:08, Pete Becker <p...@versatile coding.comwrote :
>SpreadTooThi n wrote:
>>#include <list>
class myClass
{
private:
std::string name;
std::list<myCla ssobjects;
};
At the point where myClass::object s 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
implementati on 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
Pete Becker wrote:
Gavin Deane wrote:
>On 14 Jun, 18:08, Pete Becker <p...@versatile coding.comwrote :
>>SpreadTooTh in wrote:

#include <list>
class myClass
{
private:
std::string name;
std::list<myCla ssobjects;
};
At the point where myClass::object s 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
implementatio n 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::object s 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

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

Similar topics

5
3424
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion. And so it says ANTLR. Maybe I don't understand EBNF notation. For me it should look like this. or_expr::= xor_expr | xor_expr "|" xor_expr and in ANTLR grammar file like this:
12
2572
by: Tim Clacy | last post by:
Your expertise will be appreciated... Here's a general templatised class; all specialisations of this class should have a pointer to a specialisation of the same, templatised type: template<typename T, const int N> struct Base : T { typedef Base<T, N> Type;
15
9082
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for the purpose of learning to work with C++. It therefore makes some sense for me to give the situation the amount of consideration presented below. To be quite honest, I'm amazed at the amount there is to say about such a seemingly simple...
21
4083
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class A { std::vector<B*> Bs; public:
3
3855
by: SamIAm | last post by:
Hi I have a form named form1. I have a class called class1. I want to call a recursive method in class1 called MyMethod() I would like log info to a listbox, listbox1, on the form as MyMethod performs its recursion. How do I pass an instance into class1 so that it can add items to the listbox? Should be easy I guess.
9
1664
by: Curious Student | last post by:
Some places till now, I've seen function prototypes within functions instead of in the global declaration space, which I thought was the way. I thought it was <I>only</I>: int myfunction(int, int); int main(void) {
9
2318
by: Christian E. Böhme | last post by:
Hello all, I ran into a little problem with recursive templates that I am not sure what it has to do with, essentially, since I am currently limited in my access to compilers (namely GCC 4.1) and until now had no chance of testing the code with others. It may be an implementation detail or even in the standard (which I have no access to, unfortunately). Or maybe I have hit one of those cases whose solutions are "undefined" by the...
1
4857
by: jman | last post by:
i've got an object and i'd like to recursively call a function within the class definition. (i've simplified the code ) function myclass() { this.loop = function(index) { // ..work
9
3154
by: tadmill | last post by:
Is it possible to pass a generic parameter of the same class to to its constructor, where the "T" type passed in the constructor is different than the "T" type of the instanced class? ie, public class SomeList<T> { public SomeList(SomeList<TthisSomeList)
0
9690
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
9551
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
10504
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
10251
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,...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.