我实现了以下类:
class NUMS {
int* numbers;
int size;
public:
ostream& operator << (ostream& out, NUMS const& nums) {
for (int i = 0; i < size; ++i) out << nums.numbers[i] << " \n";
return out;
}
};
class A
class B : public A {
NUMS* numbers;
public:
C& func() {
C* c = new C();
return *c;
}
ostream& operator << (ostream& out, B const& b) {
for (int i = 0; i < b.numbers->get_size(); ++i) out << b.numbers[i];
return out;
}
};
class C : public B
在我的main
:
A* a = new B();
B& b = a->func();
cout << a;
cout << b;
ostream 运算符不适用于cout << b
. 我的问题是什么?