Click here to Skip to main content
15,922,696 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ Question. Pin
WREY15-Nov-03 16:22
WREY15-Nov-03 16:22 
GeneralRe: C++ Question. Pin
Michael Dunn15-Nov-03 16:37
sitebuilderMichael Dunn15-Nov-03 16:37 
GeneralRe: C++ Question. Pin
WREY15-Nov-03 17:49
WREY15-Nov-03 17:49 
GeneralRe: C++ Question. Pin
Peter Weyzen15-Nov-03 18:26
Peter Weyzen15-Nov-03 18:26 
GeneralRe: C++ Question. Pin
Christian Graus16-Nov-03 16:22
protectorChristian Graus16-Nov-03 16:22 
GeneralHelp with searching for things in text files. Pin
Snyp15-Nov-03 12:00
Snyp15-Nov-03 12:00 
GeneralRe: Help with searching for things in text files. Pin
Peter Molnar15-Nov-03 14:42
Peter Molnar15-Nov-03 14:42 
GeneralRe: Help with searching for things in text files. Pin
Snyp15-Nov-03 14:44
Snyp15-Nov-03 14:44 
GeneralRe: Help with searching for things in text files. Pin
Antti Keskinen15-Nov-03 14:56
Antti Keskinen15-Nov-03 14:56 
GeneralRe: Help with searching for things in text files. Pin
Snyp15-Nov-03 14:59
Snyp15-Nov-03 14:59 
GeneralRe: Help with searching for things in text files. Pin
Peter Molnar15-Nov-03 14:57
Peter Molnar15-Nov-03 14:57 
GeneralRe: Help with searching for things in text files. Pin
Joe Woodbury15-Nov-03 18:57
professionalJoe Woodbury15-Nov-03 18:57 
GeneralRe: Help with searching for things in text files. Pin
Joe Woodbury15-Nov-03 18:50
professionalJoe Woodbury15-Nov-03 18:50 
General_CrtIsValidHeapPointer Pin
DougW4815-Nov-03 11:26
DougW4815-Nov-03 11:26 
GeneralWindows Explorer Pin
harsh91115-Nov-03 9:54
harsh91115-Nov-03 9:54 
GeneralRe: Windows Explorer Pin
Peter Molnar15-Nov-03 14:51
Peter Molnar15-Nov-03 14:51 
GeneralRe: Windows Explorer Pin
harsh91115-Nov-03 19:24
harsh91115-Nov-03 19:24 
GeneralRe: Windows Explorer Pin
Prakash Nadar15-Nov-03 19:51
Prakash Nadar15-Nov-03 19:51 
GeneralHTML default document icon Pin
alex.barylski15-Nov-03 8:40
alex.barylski15-Nov-03 8:40 
GeneralRe: HTML default document icon Pin
Peter Molnar15-Nov-03 14:28
Peter Molnar15-Nov-03 14:28 
GeneralRe: HTML default document icon Pin
alex.barylski15-Nov-03 14:38
alex.barylski15-Nov-03 14:38 
QuestionHow to duplicate an object? Pin
Atlence15-Nov-03 7:46
Atlence15-Nov-03 7:46 
AnswerRe: How to duplicate an object? Pin
Jeryth15-Nov-03 8:15
Jeryth15-Nov-03 8:15 
Something along the lines of
*pMyVar2 = *pMyVar1;


I just made a simple program that does the same thing and it works.

#include <iostream>
using namespace std;


class Class1
{
public:
	int var1;
	int var2;
};

int main()
{
	Class1 * object1 = new Class1();
	Class1 * object2 = new Class1();

	object1->var1 = 1;
	object1->var2 = 3;

	object2->var1 = 2;
	object2->var2 = 4;

	cout << "Object1 Var1 = " << object1->var1 << endl;
	cout << "Object1 Var2 = " << object1->var2 << endl;
	cout << "Object2 Var1 = " << object2->var1 << endl;
	cout << "Object2 Var2 = " << object2->var2 << endl << endl;

	*object2 = *object1;
	cout << "Object2 Var1 = " << object2->var1 << endl;
	cout << "Object2 Var2 = " << object2->var2 << endl;

	delete object1;
	object1 = NULL;
	delete object2;
	object2 = NULL;

	system( "pause" );
	return 0;
}


object2 was switched in the output so I don't know why it wouldn't work for a more complicated class.

The question "Do computers think?" is the same as "Can submarines swim?"
DragonFire Software

Jeryth
AnswerRe: How to duplicate an object? Pin
Tim Smith15-Nov-03 8:18
Tim Smith15-Nov-03 8:18 
GeneralRe: How to duplicate an object? Pin
Jeryth15-Nov-03 8:27
Jeryth15-Nov-03 8:27 

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.