I’m porting some C++ to Java, and encountered the following shorthand..but have no idea what this means or even how to go about Googling for it:
class mailbox {
public:
mailbox(): sent(0),received(0),msg(0) { }
I don’t understand what the method calls(?) after mailbox() signify.
Thanks.
Assuming sent, received and msg are int, it is equivalent to:
This syntax exists because, unlike Java where all objects are pointers, in C++ you can have member variables that it’s type does not have a default constructor. For exemple:
Note that in the example, even if Foo had a default constructor, Bar(int) would construct Foo twice.