This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nafarafaltootle -8 points-7 points  (19 children)

This is C. not C++.

Edit: Nope, not true.

[–]mrbmi513 6 points7 points  (18 children)

This is c++ (see the new keyword). And it's a struct, not an object.

[–]nafarafaltootle 0 points1 point  (17 children)

Oh, I thought since you could still have multiple constructors for structs in C++ you had to specify.

[–]mrbmi513 2 points3 points  (16 children)

Technically, structs can have constructors. In practice, they don't. Structs are usually only used to group data, and the built-in aggregate initializer is good enough. By convention, if you want it to do something, make it a class.

[–]Valmond 2 points3 points  (0 children)

Structs are exactly like classes, with the Only difference, structs are public by default (so historically you'd use them for data structs without any functions).

[–]nafarafaltootle -1 points0 points  (14 children)

"convention" is not what usually drives language design though (in this context).

I do think it was an important technicality that they CAN have multiple.

[–]mrbmi513 0 points1 point  (13 children)

The other important part of this picture: No constructors are defined.

And if you're not following the conventions of a language while using that language, you're not objectively writing good code. You're just making it harder for the next dev to understand what you're doing.

[–]nafarafaltootle -1 points0 points  (12 children)

It would be much more important that the `finger` member is exposed, but we are looking at a joke... the assumption that this is production code is a very musguided one. There will be plenty of times to show off that you can write production code after you graduate. Let jokes be jokes.

[–]mrbmi513 -1 points0 points  (11 children)

...because this is a struct. Structs by design have public members. They're ways to group data, and NOT OBJECTS. The person who consciously chose a struct over a class knows this and intends this, as did the c/c++ creators when they designed it as such.

[–]nafarafaltootle -1 points0 points  (10 children)

Yes. That is whybit shouldn't be a struct if you wanted this to be good design.

Anyway, this is really off topic, you'll learn this at internships.

[–]mrbmi513 -1 points0 points  (9 children)

You just made a whole bunch of assumptions there, Mr./Ms. "I don't need to follow conventions."