Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Lists

Posted on 2000-03-26
9
Medium Priority
?
236 Views
Last Modified: 2010-04-10
Hello. This is my problem:

I have defined a class which is a list: CList. The list is composed by elements of another class: CEnsemble.
OK, here is the code of the header file:

class CEnsemble
{
protected:
        CString Name;
      CEnsemble *nextNode;
        int number;
public:
      CEnsemble(CString);                  void WriteName (CString);      CString ReadName ();                  CEnsemble* GetNextPtr();      void SetNextPtr (CEnsemble*);      void SetNumber (int);
      int GetNumber();
};


class CListe: public CDialog
{
protected:
      CEnsemble* listHead;                  int NoOfNodes;            
public:
      CListe();                        void displayList();
      void deleteList();
        void InsertList(CString);             int GetNoOfNodes();
      CEnsemble* SearchList(int);
};

Now, I'd like to insert a list (CList) as a private property of CEnsemble. The problem is that the definition of CList is before the definition of CList and then it will not recognize the CList class. What can I do???

Thanks in advance.
0
Comment
Question by:javigil1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 

Expert Comment

by:LazyNerdEE
ID: 2658037
Just do a forward declaration of the class CList before the definition of the CEnsemble class as follows :

class CList;

Hope this helps,
Lazynerd.
0
 

Author Comment

by:javigil1
ID: 2658373
Upssss! Doesnt work:

So, my code would be then:

class CListe; //forward declaration. New line

class CEnsemble: public CObject
{
protected:
  CString Name;
  CEnsemble *nextNode;
  int number;
  CListe SCListe;   //New line
....

class CListe: public CDialog
{
protected:
  CEnsemble* listHead;
  int NoOfNodes;            
public:
  CListe();      //Constructor
  void displayList();
  .......


And I get this:
Compiler Error C2079
'SCListe' uses undefined class 'CListe'

0
 

Author Comment

by:javigil1
ID: 2658726
Adjusted points from 125 to 145
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:javigil1
ID: 2658727
I will try to make the whole question again:

I need help!!!

I have a list:  CListe

Code of CListe:

class CListe: public CDialog
{
protected:
     CEnsemble* listHead;
     int NoOfNodes;            
public:
     CListe();                                
     void InsertList(CString);      
     CEnsemble* SearchList(int);
};

As you can see, the members of the list are
objects from the class CEnsemble, which is so
defined:

class CEnsemble: public CObject
{
protected:
     CString Name;
     CEnsemble *nextNode;
     CListe SCList();       // <--Important!!! (i'm not sure)
public:
     CEnsemble(CString);
     void WriteName (CString);
     String ReadName ();
     CEnsemble* GetNextPtr();
     void SetNextPtr (CEnsemble*);
};

Well, in each object there's another list (SCList).
Get the idea?? A list with objects. In each object
some variables and another list.
Since CListe is declared after CEnsemble, first of
all I made a forward declaration, so that the order is:

First:
class CListe;  //forward declaration (we use it in CEnsemble)
Second:
class CEnsemble: public CObject
{
protected:
........
Third:
class CListe: public CDialog
{
protected:
......

Now I want to use the whole structure, with a code like this:

CListe lista1;
element=lista1.SearchList(1);  //I get an element of the list
element->SCListe.init();

........and the last line doesn't work. But I dont know why.
I have also tried:
      element->SCListe->init();
but i dont get anything...

Can you help me????   PLEASE!!

Thanks in advance...
0
 
LVL 4

Accepted Solution

by:
feenix earned 580 total points
ID: 2658871
One way to make it work would be to use a dynamic object and not a static one. For example:

Class CListe;

Class CEnsebmle
{
....
  CListe *SCList;
....
};

Class CListe
{
....
};

And then just initialize the SCList in the CEnsebmle's constructor. This way it will certainly work. I have never even tried to use static objects in what you're trying to do, I think it isn't even possible.
0
 

Author Comment

by:javigil1
ID: 2659002
Doesnt work:

I try to do what you say. Then I initialize  my list in
the constructor of CEnsemble, as you say:

CEnsemble::CEnsemble(CString name){    //contructor
      Name=name;
      SCList->init();
}

....I use the method init:

void CListe::init(){
      listHead = NULL;
      NoOfNodes=0;
}


but when I try to make this initialization, the program terminates and I get an error: Close/Debug/Details

0
 
LVL 4

Expert Comment

by:feenix
ID: 2660427
You did remember to create the object before trying to use it?

SCList = new CListe;
0
 

Expert Comment

by:LazyNerdEE
ID: 2661125
Try doing the same forward declaration as I said before and use a pointer to CList instead of an object of CList(Would it work?! I hope so.)
0
 

Expert Comment

by:LazyNerdEE
ID: 2661135
Oops. Sorry for my previous comment. Pls disregard it. Still my forward declaration answer holds good right?:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

705 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