Thursday, 10 May 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...