C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

circular dependencies, forward doesn't help.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
rammel
Guest





PostPosted: Fri Nov 24, 2006 10:10 am    Post subject: circular dependencies, forward doesn't help. Reply with 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.
Back to top
rammel
Guest





PostPosted: Fri Nov 24, 2006 10:11 am    Post subject: Re: circular dependencies, forward doesn't help. Reply with quote



Quote:
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

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





PostPosted: Fri Nov 24, 2006 10:11 am    Post subject: Re: circular dependencies, forward doesn't help. Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.