Solved

Lists in C++

Posted on 2000-03-26
3
169 Views
Last Modified: 2010-04-02
I have a list named CListe of objects from CEnsemble, and declared as follows:

class CListe; //forward declaration

class CEnsemble
{
...
  CListe *SCList;
...
}

class CListe
{
...
}

As you can see, there´s a list inside each element which compose the list.

I try to initialize the list inside each element in the CEnsemble´s contructor, as follows:

CEnsemble::CEnsemble(){    
   ...
   SCList->init();
}

But when I try to run the program, I get an error in this initialization:

"This program has performed an illegal operation and will be shut down. If the problem persistes...  Close/Debug/Details"

This error has nothing to do with the init method itself, since I get the error even for very simple methods.

HELP!!!!
0
Comment
Question by:caiman23
3 Comments
 
LVL 7

Accepted Solution

by:
KangaRoo earned 100 total points
ID: 2660024
Is that all relevant code?? The dot's indicate there is more that is not shown and from what is shown, there is nothing to tell.

At first glance (without seeing the dots) it would seem that SCList is not pointing at anything at all. But as said, there is too little code.
0
 
LVL 1

Expert Comment

by:yarond
ID: 2660053
KangaRoo seems to have the right answer. it seems you don't allocate anything to SCList.
The member SCList is CEnsemble is a POINTER to CListe object, and not an object in itself.
Try doing something like "SCList = new CListe" before you try to run a member function of it.
The reason the code made an illegal operation is that you just tried to run a random bit of code since SCList contained meaningless junk that your code took as an object's address.
BTW it could be a good idea to use the standard naming conventions when you write code, to avoid these things. If you'd call you pointer pList for example, it would be much more obvious to you that it's just a pointer...
0
 

Expert Comment

by:YuraPhink
ID: 2660523
KangaRoo & Yaron:
if this was the error because of not allocated place in SCList then I don't think it would give such an error.
For example, in VC++ it usually says :
"...
the memory ...:... could not be read
OK to close
CANCEL to debug
"

But this is really good idea (!)
to show more code out of this program.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now