Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

CArray - passing as parameter!

Posted on 2000-03-07
11
Medium Priority
?
344 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:gbzhhu
11 Comments
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2593956
In your CBug class you will need to refer to CellNode as CMyClass::CellNode.

0
 
LVL 12

Author Comment

by:gbzhhu
ID: 2594228
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
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2594529
Does bug.h have to be included in the CMyClass header file? Could you avoid this with a forward declaration?
0
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.

 
LVL 4

Expert Comment

by:mandhjo
ID: 2596191
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 2598855
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 2598856
This question has a deletion request Pending
0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2598938
This question no longer is pending deletion
0
 
LVL 3

Accepted Solution

by:
mnewton022700 earned 100 total points
ID: 2598939
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
 
LVL 1

Expert Comment

by:thuannc
ID: 2602957
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 2604130
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
 
LVL 12

Author Comment

by:gbzhhu
ID: 2717942
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

579 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