问题及代码:
#include <iostream>
using namespace std;
class Test
{
private:
int x;
const int y;
//************* begin *****************
public:
Test(int a, int b);
void printxy() const ; //(1)
} ;
Test::Test(int a, int b):x(a),y(b) {} ; //(2)
void Test::printxy() const //(3)
{
cout<<"x*y="<<x*y<<endl;
}
//************* end *****************
int main()
{
int x1,x2;
cin>>x1>>x2;
const Test t(x1,x2);
t.printxy( );
return 0;
}
运行结果: