1

Does it make sense to have class constuctor which takes a pointer to a object of the same class. The idea is to copy all the data for from the old object to a new object.

class Shape {
    ...
    public:
       Shape(string,string,...)
       Shape(Shape*)
}

Shape::Shape(Shape* ref) {
    layer = ref->layer;
    purpose = ref->purpose;
    ...
}
1
  • 2
    That's just a pointer version of the copy constructor. Normally it's done with a const reference. See this article for more information: en.wikipedia.org/wiki/Copy_constructor Commented Apr 10, 2012 at 2:51

1 Answer 1

1

No, this will only lead to confusing ambiguities and hard-to-catch errors (automatic conversion from pointer to object, anyone?). If initializing from a pointer make it explicit:

Shape s2 = *s1;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks nightcraker, this make more sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.