#include <iostream>
using namespace std;
class Test
{
private:
int x;
const int y;
//************* begin *****************
public:
Test(int a, int b);
void printxy() const; //(1) const 加在函数名后
} ;
Test::Test(int a, int b):x(a),y(b){} //(2) 定义构造函数
void Test::printxy() const //(3) 同1
{
cout<<"x*y="<<x*y<<endl;
}
//************* end *****************
int main()
{
int x1,x2;
cin>>x1>>x2;
const Test t(x1,x2);
t.printxy();
return 0;
}
学习总结:
const 小 结: