【发布时间】:2013-03-09 23:40:56
【问题描述】:
如果不调用 test,此代码编译没有任何问题,因此我得出结论,c++ 允许创建具有相同名称的类和函数:
class test {};
void test() {}
int main() {
test an_instance_of_test;
}
错误是:
<stdin>: In function 'int main()':
<stdin>:5:8: error: expected ';' before 'an_instance_of_test'
<stdin>:5:27: warning: statement is a reference, not call, to function 'test' [-Waddress]
而且我知道我不应该首先创建这样的明确性,但是这可能会在其他人的代码中遇到,我想问是否有办法在不更改函数或类定义的情况下解决这个问题。
【问题讨论】:
标签: c++ class function ambiguous