Hello.

I'm wondering if I'm duplicating this class by doing the following.

SimpleClass *point;
SimpleClass sc;
sc.somevalue = something;
point = new SimpleClass(sc);

This post is quite tiny, I'm not being lazy, but I couldn't think of anything else needed for this question.

Thanks :)

Recommended Answers

All 2 Replies

>I'm wondering if I'm duplicating this class by doing the following.
I'm not sure what you mean by "duplicating this class". point will point to an object that's copy constructed using sc as the argument. Whether that's a good thing or not depends on how SimpleExample is implemented. It could end up being a shallow copy, which is bad.

>>I'm wondering if I'm duplicating this class by doing the following.

Maybe. If inside the class definition contains some data members thats a pointer-to-someDataType. Then you need a deep copy. Otherwise, the pointer variable from the variable "point' with point to the same address as the pointer variable from the variable "sc", point = new SimpleClass(sc);

If inside your simpleclass, is all variables on stack, i.e does not use "new "to allocate memory from, then yes, it creates a "duplicate", i.e copies all values from the object"sc" to the object "point".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.