C++无参函数调用疑问

下面这种写法报错: error: 'SayHello' was not declared in this scope

#include <iostream>
using namespace std;

int main() {
    SayHello();
    return 0;
}

void SayHello(){
    cout<<"Hello!"<<endl;
}

下面这种写法成功编译:

#include <iostream>
using namespace std;

void SayHello(){
    cout<<"Hello!"<<endl;
}

int main() {
    SayHello();
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/loneykids/p/12287608.html