473,812 Members | 3,126 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
10 6447
On 14 Jun, 20:59, Pete Becker <p...@versatile coding.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::object s 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3426
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
9084
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
4086
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
2319
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
4858
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
3155
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
9734
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
9607
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
10664
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...
0
10404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10417
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
10139
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
9219
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
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4357
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.