
December 21st, 2012, 08:43 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 14
Time spent in forums: 2 h 56 m 35 sec
Reputation Power: 0
|
|
|
Problem with friendship
Hi, I've got a strange conundrum with friendship. I'm trying to grant a membership function of one class friendship of another.
Code:
class Cluster
{ friend Cluster Union::merge(Cluster *A, Cluster *B);
public:
Cluster();
Cluster initCluster(Cluster* L, int N){LEADER = L; NODES.push_back(N);}
Cluster *getLeader(){return LEADER;}
vector <int> getCluster(){return NODES;}
private:
Cluster *LEADER;
vector <int> NODES;
};
class Union
{
public:
void merge(Cluster *A, Cluster *B);
int getSpacing(){return SPACING;}
Union initUnion();
private:
vector <Cluster> UNION;
int SPACING;
};
void Union::merge(Cluster *A, Cluster *B)
{
A-> NODES;
}
However, there is a problem - when the IDE comes to the declaration of the friendship, it does not recognise what 'Union' is, and comes up with the error that Union is undefined - meanwhile placing the declaration of the Cluster class before the Union class would generate even more problems  . I have tried adding 'class Union;' before the declaration of the Cluster class, but that does not work either. So what is the correct way of doing this, short of just declaring one class to be a friend of another?
|