我想在main()中调用函数hi(),它是myclass类的成员
#include <iostream>
using namespace std;
class myclass
{
private:
//none
public:
void hi ();
};
void myclass::hi()
{
std::cout<<"hello world!"<<std::endl;
}
int main()
{
hi();
return 0;
}
我收到错误
/home/michael/Escritorio/deal/examples/stepup/stepup.cc: In function ‘int main()’:
/home/michael/Escritorio/deal/examples/stepup/stepup.cc:24:12: error: ‘hi’ was not declared in this scope
hi();
我也试过
myclass::hi();
我做错了什么?
由于
答案 0 :(得分:2)
您必须首先在主函数中实例化myclass,如
myclass georg;
然后你必须写georg.hi();
然后它才能工作。