?
Solved

Lists in C++

Posted on 2000-03-26
3
Medium Priority
?
184 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

850 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