C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 21st, 2012, 08:43 AM
electriceel electriceel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 14 electriceel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old December 21st, 2012, 09:03 PM
electriceel electriceel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 14 electriceel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 35 sec
Reputation Power: 0
For anyone encountering the same problem as above, it turns out that we only need to switch the classes and add a forward declaration. Then there is no more circular dependency.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Problem with friendship

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap