I'm moving from C to C++ and wondering about this decalaration, adapted from the very introduction to classes in Bjarne Stroustrup's The C++ Programming Language (Fourth Edition)
class myClass {
private:
int myvar;
public:
myClass(int i = 0) :myvar { i } { }
};
I get that this defines a constructor for myClass, taking ì as optional argument defaulting to 0, which somewhat is used as the initial value of variable myvar for the new instance of myClass. But I don't get where/how that syntax is defined, and more importantly the difference that makes with:
class myClass {
private:
int myvar;
public:
myClass(int i = 0) {
myvar = i;
}
};