区分int a() 和 int a
事因
#include <iostream>
using namespace std;
struct A
{
    A(int) {}
    A() {}
    void fun() {};
};
int main()
{
    A a(2);
    a.fun();
    A b();
    b.fun();
}
编译错误

解释
A b(); 是函数声明,返回值为A, 函数名为b
不信你看
#include <iostream> using namespace std; int main() { int test(); cout << test << endl; cout << test() << endl; } int test() { return 1000; }
结果

鄙视下自己
今天才知道函数里边还可以声明函数(不可以定义)的。不信你看
#include <iostream>
using namespace std;
int main()
{
	int test();
	cout << test << endl;
	cout << test() << endl;
}
int test()
{
	void test1();
	test1();
	return 1000;
}
void test1()
{
	cout << "I'm here" << endl;
}
结果

                    
                
                
            
        
浙公网安备 33010602011771号