c++ - 为什么 (new Foo())->baa() 有效而 new Foo()->baa() 无效?

标签 c++ operators

为什么 (new Foo())->baa() 有效而 new Foo()->baa() 无效?它与 -> 优先级或类似的东西有关吗?我不知道如何调用它,我是 C++ 的新手...

最佳答案

这是因为 operator precedence . ()->new 具有更高的优先级,因此第二个表达式被视为您编写了:

new ( ( (Foo() -> baa)() ) )

关于c++ - 为什么 (new Foo())->baa() 有效而 new Foo()->baa() 无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22235965/

相关文章:

c++ - 无法使用 VideoWriter 从网络摄像头捕获中写入

C++,实例化 std::vector 时性能不佳

c - 在 C 中使用 '*' 作为 'value at' 运算符

python - 为什么 python list L += x 的行为与 L = L + x 不同?

html - 什么是 : operator

c++ - 下面的程序在 C++ 中如何工作?

c++将unique_ptr作为对另一个函数的引用传递

dart - 什么是 ?? Dart 中的双问号?

C++ - 重载 += 运算符

java - 使用 OpenSSL 的多个连接