Click here to Skip to main content
15,888,521 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionInterdependent classes Pin
CoolASL15-Aug-06 0:24
CoolASL15-Aug-06 0:24 
AnswerRe: Interdependent classes Pin
Maxwell Chen15-Aug-06 0:33
Maxwell Chen15-Aug-06 0:33 
GeneralRe: Interdependent classes Pin
CoolASL15-Aug-06 5:31
CoolASL15-Aug-06 5:31 
AnswerRe: Interdependent classes Pin
Christian Graus15-Aug-06 2:12
protectorChristian Graus15-Aug-06 2:12 
GeneralRe: Interdependent classes Pin
CoolASL15-Aug-06 3:58
CoolASL15-Aug-06 3:58 
GeneralRe: Interdependent classes Pin
Christian Graus15-Aug-06 11:03
protectorChristian Graus15-Aug-06 11:03 
GeneralRe: Interdependent classes Pin
CoolASL15-Aug-06 22:07
CoolASL15-Aug-06 22:07 
AnswerRe: Interdependent classes [modified] Pin
Zac Howland15-Aug-06 9:42
Zac Howland15-Aug-06 9:42 
You really should rethink your design here. Having classes that are inter-dependent is not easy to write, and become impossible to maintain. There are tons of options you can take for making this code cleaner, but I will only provide one here:

class Two;
class Three;

class One
{
private:
	int _One;
public:
	std::tr1::shared_ptr<Two*> _Two;
	std::tr1::shared_ptr<Three*> _Three;

	One() : _Two(new Two), _Three(new Three)
	{
	}	
};

class Two
{
private:
	int _Two;
public:
	std::tr1::shared_ptr<One*> _One;
	std::tr1::shared_ptr<Three*> _Three;

	Two() : _One(new One), _Three(new Three)
	{
	}
};

class Three
{
private:
	int _Three;
public:
	std::tr1::shared_ptr<One*> _One;
	std::tr1::shared_ptr<Two*> _Two;

	Three() : _One(new One), _Two(new Two)
	{
	}
};


The best solution, however, would be to redesign these classes such that they are not inter-dependent.

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

GeneralRe: Interdependent classes Pin
BadKarma15-Aug-06 21:07
BadKarma15-Aug-06 21:07 
GeneralRe: Interdependent classes Pin
CoolASL15-Aug-06 22:09
CoolASL15-Aug-06 22:09 
GeneralRe: Interdependent classes Pin
Zac Howland16-Aug-06 5:01
Zac Howland16-Aug-06 5:01 
GeneralRe: Interdependent classes Pin
CoolASL15-Aug-06 22:08
CoolASL15-Aug-06 22:08 
QuestionFile reading and writing Pin
69 Bay14-Aug-06 23:51
69 Bay14-Aug-06 23:51 
AnswerRe: File reading and writing Pin
Christian Graus15-Aug-06 0:03
protectorChristian Graus15-Aug-06 0:03 
GeneralRe: File reading and writing Pin
69 Bay15-Aug-06 5:10
69 Bay15-Aug-06 5:10 
GeneralRe: File reading and writing Pin
Zac Howland15-Aug-06 9:50
Zac Howland15-Aug-06 9:50 
GeneralRe: File reading and writing Pin
69 Bay16-Aug-06 2:34
69 Bay16-Aug-06 2:34 
GeneralRe: File reading and writing Pin
Zac Howland16-Aug-06 5:05
Zac Howland16-Aug-06 5:05 
GeneralRe: File reading and writing Pin
Christian Graus15-Aug-06 11:03
protectorChristian Graus15-Aug-06 11:03 
QuestionRe: File reading and writing Pin
David Crow15-Aug-06 4:08
David Crow15-Aug-06 4:08 
AnswerRe: File reading and writing Pin
69 Bay15-Aug-06 5:05
69 Bay15-Aug-06 5:05 
QuestionIActiveDesktop Pin
Rinu_Raj14-Aug-06 23:03
Rinu_Raj14-Aug-06 23:03 
AnswerRe: IActiveDesktop [modified] Pin
Rinu_Raj14-Aug-06 23:08
Rinu_Raj14-Aug-06 23:08 
AnswerRe: IActiveDesktop Pin
Hamid_RT14-Aug-06 23:18
Hamid_RT14-Aug-06 23:18 
Questionsecurity library for Windows Mobile? Pin
George_George14-Aug-06 22:48
George_George14-Aug-06 22:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.