Saturday 23 November 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...