CArray - passing as parameter!

Hi I am using VC++ 6.

I have two CArray declared as

      CArray <CellNode, CellNode> GridCells;
      CArray <CBug, CBug> BugArray;

CellNode is a struct in class CMyClass and CBug is another class.
I am having a problem with a method in CBug which I pass GridCells declared above.  The method is declared as:

      void MoveBug(CArray <CellNode, CellNode>&);

The problem is that CellNode struct is part of and declared in CMyClass
and the method in CBug above seems to need it because of the template CArray passed.  I cannot declare  another CellNode as that will not work and I cannot take CellNode declaration out of CMyClass (that is where it belongs).

How can this be solved?

ps.  CBug is included in CMyClass as #include "Bug.h" and including CMyClass in CBug does not seem to work

Bear with me I am pretty new to this.
LVL 12
gbzhhuAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mnewton022700Connect With a Mentor Commented:
I'm not going for points here, this is just fyi.

You can forward declare CBug in the header file of CMyClass and then include bug.h in the implementation file of CMyClass.

As long as you don't actually instantiate or use a CBug object in the header file of CMyClass this should avoid the catch22 situation.
0
 
mnewton022700Commented:
In your CBug class you will need to refer to CellNode as CMyClass::CellNode.

0
 
gbzhhuAuthor Commented:
but CBug class does not know the existance of CMyClass.  You can't have CMyClass::CellNode in CBug unless CMyClass was included in CBug
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mnewton022700Commented:
Does bug.h have to be included in the CMyClass header file? Could you avoid this with a forward declaration?
0
 
mandhjoCommented:
You mentioned you were new to this, so just in case:

a forward declaration for a class looks like this:

class CBug;


You can get away with this in your header file as long as you don't use any of the functionality (like calling a member function of the CBug class) of the CBug class *in the header file itself*.
0
 
gbzhhuAuthor Commented:
Thank you chaps.

Forward declaration will not help as I actually construct objects of CBug in CMyClass ie.

CBug aBug();

This will not work for forward declaration.
As this is a catch 22 situation I have rearranged my design and solved the problem ( I added a helper class which is connected to both CBug and CMyCalss.

I will now delete the question.  should you feel your answer solved the problem and I unfairly deleted the question, please put a comment

Cheers
0
 
gbzhhuAuthor Commented:
This question has a deletion request Pending
0
 
mnewton022700Commented:
This question no longer is pending deletion
0
 
thuanncCommented:
I think you should declare CellNode struct in other golbal file and then include it in both CBug.h and MyClass.h
Hope this help!
thu@nnc
0
 
gbzhhuAuthor Commented:
Thank you both mnewton and thuannc for the comments.

I have already done a lot of change to my code (redesigned as I said above) and it seems to work fine.

The question should be pending deletion!! as no answer helped me solve it, though I learned more about forward declaration.

I will leave it to customer service to decide whether it is ethical to delete it or not.
0
 
gbzhhuAuthor Commented:
This was as forced answer, I have already deleted the question and solved my problem by myself.  You said you were not going for points, but i could not delete the question after you answered, so I had to accept your answer.  Well.... it is only 50 points.  I knew forward declaration ( I am new to C++ but that new - forward declaration is basic stuff)

Thanks by the way.

Hassan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.