 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
rammel Guest
|
Posted: Fri Nov 24, 2006 10:10 am Post subject: circular dependencies, forward doesn't help. |
|
|
class1.h
-----------
#ifndef CLASS1_H_
#define CLASS1_H_
#include "class2.h" // inclusion
class class2; // and forward
class class1
{
private:
class2 aRererence;
// --- gcc says: "error: field 'aRererence' has incomplete type" ---
public:
class1() :aReference( class2& aR ) {aReference = aR;};
// --- error according to the missing type of aReference ---
};
#endif /*CLASS1_H_*/
------------
class2.h
------------
#ifndef CLASS2_H_
#define CLASS2_H_
#include <vector>
#include "class1.h" // inclusion
class class1; // and forward
class class2
{
private:
std::vector<class1> someContainer;
public:
class2();
};
#endif /*CLASS2_H_*/
-----------------------------------------
What is the correct way around this error? I guess I could declare the
field as pointer, but I wanted to use the c++ reference mechanism.
Thanks for your help in advance. |
|
| Back to top |
|
 |
rammel Guest
|
Posted: Fri Nov 24, 2006 10:11 am Post subject: Re: circular dependencies, forward doesn't help. |
|
|
Beeing a c++ newbie I have to admit that I was unable to get the point
from that discussion. So could you please be so kind and alter the
right line of my code?
I've read about the rules when to use forward or inclusion and tried
the most combinations without success.
I think I can't put out one of the includes because class1 holds an
vector of class2-elements and class2 needs a referece to the class1 it
sticks in.
I also have no clue how to redesign this without losing functionality. |
|
| Back to top |
|
 |
Hooyoo Guest
|
Posted: Fri Nov 24, 2006 10:11 am Post subject: Re: circular dependencies, forward doesn't help. |
|
|
rammel wrote:
| Quote: | class1.h
-----------
#ifndef CLASS1_H_
#define CLASS1_H_
#include "class2.h" // inclusion
class class2; // and forward
class class1
{
private:
class2 aRererence;
// --- gcc says: "error: field 'aRererence' has incomplete type" ---
public:
class1() :aReference( class2& aR ) {aReference = aR;};
// --- error according to the missing type of aReference ---
};
#endif /*CLASS1_H_*/
------------
class2.h
------------
#ifndef CLASS2_H_
#define CLASS2_H_
#include <vector
#include "class1.h" // inclusion
class class1; // and forward
class class2
{
private:
std::vector<class1> someContainer;
public:
class2();
};
#endif /*CLASS2_H_*/
-----------------------------------------
What is the correct way around this error? I guess I could declare the
field as pointer, but I wanted to use the c++ reference mechanism.
Thanks for your help in advance.
|
The same question I asked before:
"How to solve this problem?"
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/84b329563953d770/5f1f69a762f5a2ac?hl=en#5f1f69a762f5a2ac |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|