我是靠谱客的博主 唠叨服饰,这篇文章主要介绍使用Foo f2();f2.bar();带来的问题,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Foo { public: Foo() {}; Foo(int a) {}; void bar() {}; }; int main() { // this works... Foo foo1(1); foo1.bar(); // this does not... Foo foo2(); foo2.bar(); return 0; }
err:
复制代码
1
2
nonclass.cpp: In function ‘int main(int, const char**)’: nonclass.cpp:17: error: request for member ‘bar’ in ‘foo2’, which is of non-class type ‘Foo ()()’

原因:

because compiler thinks of
Foo foo2()
as of function declaration with name 'foo2' and the return type 'Foo'.

最后

以上就是唠叨服饰最近收集整理的关于使用Foo f2();f2.bar();带来的问题的全部内容,更多相关使用Foo内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部