Sunday, 4 June 2017

c++ - Does curly brackets matter for empty constructor?




I'm wondering if the following constructors are the same for C++:



class foo
{
public:
foo(void){};
...
}


and



class foo
{
public:
foo(void);
...
}


Do curly brackets matter for these two cases? Thanks much!


Answer



They're not same. {} represents a regular function-body and makes the former function definition.



foo(void){}; // function definition
foo(void); // function declaration

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...