Solved

Lists in C++

Posted on 2000-03-26
3
168 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

744 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

16 Experts available now in Live!

Get 1:1 Help Now