I've been taking a look at how to create an instance of a class in C++. There seem to be several ways of doing this:
ClassExample classExample1;
ClassExample classExample2();
ClassExample classExample3(void);
ClassExample classExample4 = ClassExample();
1 and 4 call the default constructors. When I use 2 and 3, I can't seem to refer to the variables and they are not initialised. In the debugger, they are stepped over. Why is this? Are these the same? What is the difference? Is there a preferred option?
When we have parameters to pass there are two ways of doing this:
ClassExample classExample1(true, 1, "");
ClassExample classExample2 = ClassExample(true, 1, "");
Again, is there a difference? what is the preferred option?
UPDATE
C++ 11 also introduced this form of initialization:
ClassExample classExample2{ };
which is the equivelant of:
ClassExample classExample2();