How can I clone an object in C++, so it is a seperate object, but exactly the same as the original?
Thanks,
- Moshe
Jump to PostYou can use the default copy constructor, like this:
struct myObject { int data[10]; }; int main() { myObject a; /* Do stuff to 'a' */ myObject b( a ); /* 'b' is identical to 'a' now */ return 0; }
You can use the default copy constructor, like this:
struct myObject {
int data[10];
};
int main() {
myObject a;
/* Do stuff to 'a' */
myObject b( a );
/* 'b' is identical to 'a' now */
return 0;
}
Thanks for the prompt and informative response!
- Moshe
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.