我想知道为什么不能从静态函数调用成员函数
#include <iostream>
class A{
public:
A(){}
~A(){}
static void astaticFunction(){
printHello();
}
private:
void printHello(){
std::cout << "Hello" << std::endl;
}
};
int main(int argc, char **argv){
A::astaticFunction();
return 0;
}
编译器正在返回这个
main.cpp: In static member function ‘static void A::astaticFunction()’:
main.cpp:8:16: error: cannot call member function ‘void A::printHello()’ without object
我该如何使用它?谢谢