use of brackets after contructor and destructor

Hello, what is the difference between

1
2
 Mammal();
~Mammal();

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
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.
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
Thank you very much for your responses.
Topic archived. No new replies allowed.