【发布时间】:2017-02-17 03:09:10
【问题描述】:
#include <iostream>
using namespace std;
struct A
{
A()
{
cout << "A::A()" << endl;
}
};
int A()
{
cout << "void A()" << endl;
return 0;
}
int main()
{
auto v = A();
}
输出是:
void A()
为什么 C++ 允许函数和类同名?
【问题讨论】:
-
设计师做出了这个决定,但没有人改变它......不确定你在寻找什么其他答案。也许是为了兼容 C 代码或其他现有代码
-
我问,为什么不呢?只是为了不让人迷惑自己?
-
我投票决定将此问题作为题外话结束,因为它应该发给 Bjarne Stroustrup。其他任何事情都或多或少是不知情的意见。
标签: c++ function class standards language-design