Does curly brackets matter for empty constructor?
This question already has an answer here:
They're not same. {}
represents a regular function-body and makes the former function definition.
foo(void){}; // function definition
foo(void); // function declaration
Yes they do. The second one will generate undefined reference to foo::foo
(unless defined in another place). If you can use C++11 or above, you can use
foo()=default;
to define a compiler generated constructor
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than the constructor would not already implicitly do.
In the second case, without them, the compiler will expect an implementation elsewhere - such as a .cpp file.
链接地址: http://www.djcxy.com/p/40620.html上一篇: 在c中声明vs定义变量
下一篇: 花括号对空构造函数是否重要?