问题及代码
*ALL rights reserved.
*文件名称: 初学对象5
*作者:李长鸿
*完成时间:2015.4.8
*问题描述:阅读程序
*/
#include <iostream>
using namespace std;
class base
{
private:
int m;
public:
base() {};
base(int m){this->m=m;}
int get(){return m;}
void set(int m){this->m=m;}
};//base_end
int main()
{
base *ptr;
ptr=new base[2];
ptr->set(30);
ptr=ptr+1;
ptr->set(50);
base a[2]= {1,9};
cout<<a[0].get()<<","<<a[1].get()<<endl;
cout<<ptr->get()<<",";
ptr=ptr-1;
cout<<ptr->get()<<endl;
delete[] ptr;
return 0;
}
总结:结果是对,可是不太明白。base() {}; base(int m){this->m=m;},两个base起的什么作用啊?调用应该是调用的第二个,那第一个在这儿。。。不是很碍事?