use of brackets after contructor and destructor
May 18, 2015 at 8:01am UTC
Hello, what is the difference between
and
1 2
Mammal() {}
~Mammal() {}
Why it is not needed to put semicolons after the lines in the second piece of code.
Thanks in advance
May 18, 2015 at 8:05am UTC
The first two examples are invocations, while in the last two examples you are providing an empty implementation of both the constructor and the destructor.
May 18, 2015 at 9:46am UTC
The first two examples are invocations
They are probably function declarations.
1 2 3 4 5 6 7
class Mammal
{
public :
Mammal();
~Mammal();
// ...
};
It means they have to be defined elsewhere, outside the class definition.
1 2 3 4 5 6 7 8 9
Mammal::Mammal()
{
// ...
}
Mammal::~Mammal()
{
// ...
}
Last edited on May 18, 2015 at 9:47am UTC
May 18, 2015 at 1:55pm UTC
Thank you very much for your responses.
Topic archived. No new replies allowed.