Thursday, May 10, 2018

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...