c++错误提示_c++编译错误
#include<iostream>
using namespace std;
class myarray{
public:
myarray(int leng);
void input();
void display();
~myarray();
protect:
int *alist;
int length;
};
myarray::myarray(int leng)
{
length=leng;
}
void myarray::input()
{
int i;
alist=new int[length];
for(i=0;i<length;i++)
{
cin>>alist[i];
}
}
void myarray::display()
{
int i;
for(i=0;i<length;i++)
cout<<alist[i];
}
myarray::~myarray()
{
cout<<"the obj has been released"<<endl;
}
void main()
{
myarray a(4);
a.input();
a.display();
}
Microsoft Visual Studio\MyProjects\f\ds.cpp(10) : error C2062: type 'int' unexpected
D:\Microsoft Visual Studio\MyProjects\f\ds.cpp(10) : error C2238: unexpected token(s) preceding ';'
D:\Microsoft Visual Studio\MyProjects\f\ds.cpp(20) : error C2065: 'alist' : undeclared identifier
D:\Microsoft Visual Studio\MyProjects\f\ds.cpp(20) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\Microsoft Visual Studio\MyProjects\f\ds.cpp(23) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\MyProjects\f\ds.cpp(23) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
D:\Microsoft Visual Studio\MyProjects\f\ds.cpp(30) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
是语法错了吗?
最佳答案
那叫做“protected”,而不是“protect”……
另外,既然没有用到继承,建议用“private”。
其他回答
暂无其它回答!