【发布时间】:2014-02-02 14:33:40
【问题描述】:
#include <iostream>
class Abc // created class with name Abc
{
void display()//member function
{
cout<<"Displaying NO."<<endl;
}
};
int main()
{
Abc obj;//creating object of the class
obj.display();//calling member function inside class
}
它返回错误
main.cpp: In function 'int main()':
main.cpp:5:10: error: 'void Abc::display()' is private
void display()
^
main.cpp:13:17: error: within this context
obj.display();
^
我试图让显示功能public int main 但随后它给出了错误
main.cpp:5:11: error: expected ':' before 'void'
public void display()
^
【问题讨论】:
-
错误消息是非常描述性的。
class中的默认访问说明符是private。 -
彻底阅读书籍,不要只是看一眼就开始编程
标签: c++