Click here to Skip to main content
15,909,829 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Auto-Code of MFC Classes Pin
baerten16-Nov-07 2:32
baerten16-Nov-07 2:32 
GeneralRe: Auto-Code of MFC Classes Pin
Nelek16-Nov-07 4:02
protectorNelek16-Nov-07 4:02 
QuestionHow to make package? Pin
H4u3215-Nov-07 23:52
H4u3215-Nov-07 23:52 
AnswerRe: How to make package? Pin
Nelek16-Nov-07 0:04
protectorNelek16-Nov-07 0:04 
GeneralRe: How to make package? Pin
H4u3216-Nov-07 0:42
H4u3216-Nov-07 0:42 
GeneralRe: How to make package? Pin
H4u3216-Nov-07 0:42
H4u3216-Nov-07 0:42 
QuestionHow to write copy constructor when returning any template object. Pin
Atul2315-Nov-07 22:06
Atul2315-Nov-07 22:06 
AnswerRe: How to write copy constructor when returning any template object. Pin
Nelek15-Nov-07 22:29
protectorNelek15-Nov-07 22:29 
I made a lot of different objects in my project deriving from CObject. In all of them I have the constructor/destructor, copy and assingment operators, and in just some the equality operator
//header.h
	CMyObject();
	CMyObject(const CMyObject &obj);		// Copy operator
	CMyObject& operator= (const CMyObject &obj);	// Assigment Operator
	BOOL operator== (const CMyObject &obj);		// Equalty operator
	virtual ~CMyObject();


and I code them following this schema

CMyObject::CMyObject()
{	m_dVar1 = 0.0;
	m_bVar2 = FALSE;
	//and so on
}

//***********

CMyObject::CMyObject(const CMyObject &obj)
{	m_dVar1 = obj.m_dVar1;
	m_bVar2 = obj.m_bVar2;
	// and one more for every member variable that the class owns
}

//***********

CMyObject& CMyObject::operator= (const CMyObject &obj)
{	m_bVar1 = obj.m_bVar1;
	m_bVar2 = obj.m_bVar2;
	// and one more for every member variable that the class owns
	return *this;
}

//***********

BOOL CMyObject::operator== (const CMyObject &obj)
{	return ((this->m_bVar1 == obj.m_bVar1) && 
		(this->m_bVar2 == obj.m_bVar2) &&
	// and one more for every member variable that the class owns
		);
}

//***********

CMyObject::~CMyObject()
{
//if the object has lists or arrays, delete the contents...
//free possible used memory...
}


With this schema you can use the object in arrays, in lists, just as independant object and make operations and so on. Up to complicated hierachies of objects that are owned from other objects. (For more info about what I mean take a look into my answers in the comments of my article SmartListII[^], I wrote there more or less the structure I use with the objects in one project, using lists, arrays and so on)

Greetings.

--------
M.D.V. Wink | ;)

If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

Help me to understand what I'm saying, and I'll explain it better to you

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

AnswerRe: How to write copy constructor when returning any template object. Pin
codeII15-Nov-07 22:31
codeII15-Nov-07 22:31 
AnswerSure? Pin
CPallini15-Nov-07 22:31
mveCPallini15-Nov-07 22:31 
AnswerYou are missing quite a lot of braces here [modified] Pin
jhwurmbach16-Nov-07 3:43
jhwurmbach16-Nov-07 3:43 
GeneralRe: You are missing quite a lot of braces here Pin
CPallini16-Nov-07 4:30
mveCPallini16-Nov-07 4:30 
GeneralRe: You are missing quite a lot of braces here Pin
jhwurmbach18-Nov-07 22:04
jhwurmbach18-Nov-07 22:04 
GeneralRe: You are missing quite a lot of braces here Pin
CPallini18-Nov-07 22:24
mveCPallini18-Nov-07 22:24 
GeneralRe: You are missing quite a lot of braces here Pin
jhwurmbach18-Nov-07 22:35
jhwurmbach18-Nov-07 22:35 
GeneralRe: You are missing quite a lot of braces here Pin
CPallini18-Nov-07 22:46
mveCPallini18-Nov-07 22:46 
GeneralRe: You are missing quite a lot of braces here [modified] Pin
jhwurmbach18-Nov-07 22:48
jhwurmbach18-Nov-07 22:48 
GeneralOh, that isn't correct Pin
CPallini18-Nov-07 22:54
mveCPallini18-Nov-07 22:54 
GeneralRe: Oh, that isn't correct Pin
jhwurmbach18-Nov-07 23:01
jhwurmbach18-Nov-07 23:01 
GeneralRe: You are missing quite a lot of braces here Pin
CPallini18-Nov-07 23:21
mveCPallini18-Nov-07 23:21 
GeneralRe: You are missing quite a lot of braces here Pin
jhwurmbach18-Nov-07 23:27
jhwurmbach18-Nov-07 23:27 
GeneralRe: You are missing quite a lot of braces here Pin
CPallini18-Nov-07 23:37
mveCPallini18-Nov-07 23:37 
GeneralRe: You are missing quite a lot of braces here Pin
David Crow16-Nov-07 11:04
David Crow16-Nov-07 11:04 
GeneralRe: You are missing quite a lot of braces here Pin
jhwurmbach18-Nov-07 22:20
jhwurmbach18-Nov-07 22:20 
GeneralRe: You are missing quite a lot of braces here Pin
David Crow19-Nov-07 3:17
David Crow19-Nov-07 3:17 

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.