我有一小段代码有一个声明 void();
int main()
{
void( ); // 1: parses fine in GCC 5.4.0 -Wpedantic
// void; // 2: error declaration does not declare anything
}
Run Code Online (Sandbox Code Playgroud)
什么是1 void()
?
是什么让1 void()
与2不同void;
?
我已经读过了:
但我很好奇松散的声明是否为void(); 不同于其中之一(当然为什么)
不明白为什么return std::set<int>();
还给空了std::set<int>
.是否有运营商超载的operator ()
在std::set
上课吗?我假设它std::set<int>()
是一个函数,而不是一个对象!这个函数定义在哪里?
似乎默认构造函数std::set<int> s;
与表达式相同std::set<int>()
???
谢谢你的回复...似乎我不懂C++基础知识......
您不能声明void
变量:
void fn() {
void a; // ill-formed
}
Run Code Online (Sandbox Code Playgroud)
但这编译为:
void fn() {
void(); // a void object?
}
Run Code Online (Sandbox Code Playgroud)
什么void()
意思 有什么用?为什么void a;
格式不正确,但void()
可以?
void fn() {
void a = void(); // ill-formed
}
Run Code Online (Sandbox Code Playgroud)