How can I clone an object in C++, so it is a seperate object, but exactly the same as the original?

Thanks,
- Moshe

Recommended Answers

You can use the default copy constructor, like this:[CODE=CPLUSPLUS]struct myObject {
int data[10];
};

int main() {
myObject a;

/ Do stuff to 'a' /

myObject b( a );

/ 'b' is identical to 'a' now /

return 0;
}[/CODE]

Jump to Post

All 2 Replies

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;
}
commented: Absolutely right :P +3

Thanks for the prompt and informative response!

- Moshe