输入样例: 1 2
3 4
输出样例: [1,2] -> 6
代码框架:
#include <iostream>
#include <string>
class A;
namespace myns
{
class COUT
{
public:
COUT() {}
void operator<<(const char a[]); // 成员函数
myns::COUT operator<<(A b); // 成员函数
};
COUT cout;
}
class A
{
public:
A(int x, int y) : w(x), h(y) {}
int getLen() const
{
if (len < 0)
len = 2 * (w + h);
return len;
}
private:
// todo ____qcodep____
int w, h;
mutable int len = -1;
};
// todo ____qcodep____
using myns::cout;
using std::cin;
int main()
{
int x, y;
cin >> x >> y;
A a1(x, y);
cout << a1 << "\n"; // first myns::COUT operator<<, then void operator<<
cin >> x >> y;
A a2(x, y);
cout << a2 << "\n";
return 0;
}