c++初学者--简单的this指针引用

#include<iostream>
using namespace std;
class stock
{
public:
stock()
{
cout<<"stock code="<<endl;
}
stock(int code,int q=1000,int p=3000):stockcode(code),quantity(q),price(p){}
void show()
{
cout<<this->stockcode<<"   "<<this->quantity<<"   "<<this->price<<endl;
}
private:
int stockcode,quantity,price;
};
int main()
{
stock p(2),a(1,2,3);
p.show();
a.show();
return 0;
}

猜你喜欢

转载自blog.csdn.net/zhouzhou_98/article/details/80722834