I have the following Stack class.
class Stack{
public:
int size;
int* x;
Stack() : size(10), x(new int[10]) {}
Stack(const Stack& s) : x(new int[size=s.size]) {}
};
Notice the assignment in the copy constructor. The code works, compile fine and compiler (gcc) doesn't complain even with -Wall -Wextra
flags. Does the compiler automatically rewrite the compiler to this?
Stack(const Stack& s) : size(s.size), x(new int[size]) {}
Or is there some other magic? I noticed when I change the definition order, the compiler complaints about not-in-order initialization. So I assume it's the case I mentioned. I couldn't find anything in the documentation and the ASM output doesn't help me either.