CArray - passing as parameter!

Posted on 2000-03-07
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.
Question by:gbzhhu
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

Expert Comment

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

LVL 12

Author Comment

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

Expert Comment

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


Expert Comment

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*.
LVL 12

Author Comment

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

LVL 12

Author Comment

ID: 2598856
This question has a deletion request Pending

Expert Comment

ID: 2598938
This question no longer is pending deletion

Accepted Solution

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.

Expert Comment

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!
LVL 12

Author Comment

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.
LVL 12

Author Comment

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.


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