#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();
}
空隙A()
为什么C++允许函数和类具有相同的名字?
设计师做出了这个决定,没有人改变它......不知道你在找什么其他答案。也许是为了兼容C代码或其他现有代码 –
我问,为什么不呢?只是为了不让人们迷惑自己? – csmckelvey
我投票结束这个问题作为题外话,因为它应该发给Bjarne Stroustrup。其他任何事情都只是或多或少的不知情的意见。 – EJP