Solved

CArray - passing as parameter!

Posted on 2000-03-07
11
333 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
[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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 50 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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