为什么用未申报的变量工作调用函子
Why does calling a functor with an undeclared variable work?
class foo {
public:
bool operator () (int & i) {
return true;
}
};
int main() {
foo(WhyDoesThisCompile);
return 0;
}
将WhyDoesThisCompile
(无空间(传递给函子时,程序会编译。
为什么?我在clang 4.0.0中进行了测试。
您不调用函数。
您正在声明foo
,称为WhyDoesThisCompile
。
是,尽管有括号。
我想你的意思是:
foo()(WhyDoesThisCompile);
// ^^^^^
// temp ^^^^^^^^^^^^^^^^^^^^
// of invocation of op()
// type
// `foo`
…不是。
相关文章:
- 即使没有调用这个递归函数,它是如何工作的?
- 这个C++编译器优化(在自身的实例上调用对象自己的构造函数)的名称是什么,它是如何工作的?
- 推理类型如何工作"auto"和按引用调用?
- 以下代码如何工作以每次为唯一调用堆栈唯一实例化模板函数?
- 递归函数调用在后台工作
- std::async 如何工作:为什么它会调用这么多次复制/移动?
- QLibrary 函数在第一次调用时工作缓慢
- 工作线程一直在等待,condition_variable甚至调用了notify_all
- 虚拟基类在内部如何工作?编译器如何解析对基方法的调用?
- 在新作用域中使用unique_lock是否等效于在使用共享资源的工作结束时解锁调用
- 从Excel VBA调用C++DLL只能从Visual Studio中的调试实例工作
- 异步操作的 Asio 处理程序在其同步对应项正常工作时不会调用
- 如何使功能"run"工作。程序在调用运行时退出
- 当在函数调用中递增值时,程序正常工作,但是如果我们在单独的行中增加值而不是呼叫函数,则会出现错误.为什么
- 在线程中调用线程会给我带来错误,如果我只调用该函数,则可以正常工作
- boost::asio 使用 post() 时没有调用处理程序,当直接调用函数时有效(io_context有工作)
- 为什么用未申报的变量工作调用函子
- 引用调用在 c++ 中如何工作?
- winsock连接调用崩溃如果多个线程运行,则在一个线程中正常工作
- C Google Mock -Expect_Call() - 期望在不直接调用时无法正常工作