Don't name your class "class
", as it is a reserved name.
As for C++, if the constructor takes no parameters, you instantiate it using
Foo a; // note, if you are using c++11, you can do Foo a{};
As opposed to:
Foo b();
Which actually does something totally unexpected*, and declares a function named b
that returns a Foo
instance.
As for Foo c(null)
, it won't compile as there is no default constructor that takes an argument.
* It is referred to as "the most vexing parse", though I find that to be an exaggeration. It can certainly catch you by surprise, but just knowing that you can declare a function prototype inside a function, should be enough to remove the "vexing" aspect.
In other words int getMyInt();
is obviously a function prototype when placed outside any function definitions. However, since this is also the case when inside a function definition, int getMyInt();
doesn't do anything it wouldn't normally do... which is to define a function prototype getMyInt
that returns an integer.