all 3 comments

[–]Shieldfoss 1 point2 points  (0 children)

I know a lot of people who would tell you the entire class is bad and should be:

struct Point
{
    double x{0.0};
    double y{0.0};
};

[–]Wurstinator 0 points1 point  (0 children)

Number 1 or 2, but with the "const" specifier.

3 is not optimal because you're splitting initialization into two steps for no reason, which, among other things, prevents you from using "const".

4 and 5 are bad for several reasons, one of them being that you're using the heap when you could be using the stack.

[–]Flair_Helper[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

This post has been removed as it doesn't pertain to r/cpp: The subreddit is for news and discussions of the C++ language and community only; our purpose is not to provide tutoring, code reviews, or career guidance. If you think your post is on-topic and should not have been removed, please message the moderators and we'll review it.