c++错误提示_c++编译错误

原问题:c++编译错误
分类:编程开发 > 最后更新时间:【2017-05-12 22:07:30】
问题补充:

#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”。

最佳答案由网友  BIRD11329  提供
公告: 为响应国家净网行动,部分内容已经删除,感谢网友理解。
17

分享到:

其他回答

暂无其它回答!

    推荐
  • C++编译错误