//my template class
#include "shape.h"
#include <iostream>
using namespace std;
template <typename T>
//error : shadows template parm????
class CCircle : public CShape {
private:
T Radius;
public:
CCircle() {}
CCircle(int a, int b, T r) {
x = a;
y = b;
Radius = r;
}
double GetArea() {
return Radius * Radius * 3.14;
}
void Print() {
cout << GetArea() << endl;
}
template <typename T>
friend ostream& operator << (ostream& out, CCircle<T>& Po);
template <typename T>
CCircle operator+(const CCircle<T>& p) {
return CCircle(x, y, Radius + p.Radius);
}
};
template <typename T>
ostream& operator << (ostream& out, CCircle<T>& Po) {
out << "Area: " << Po.GetArea() << endl;
return out;
}
Asked
Active
Viewed 32 times
-3
Olaf Dietsche
- 69,448
- 7
- 95
- 188
김민겸
- 1
-
Show exact error message, please. Also provide dependencies, how does `CShape` look like? Currently, nobody is able to tell you anything. And finally, what is your question? – Olaf Dietsche Jun 03 '22 at 08:11
-
please read about [mcve]. As you are including a non-disclosed header others cannot reproduce the error, hence it is important that you at least provide the exact error message. Anyhow, `operator+` has a template parameter of same name as the class template, thats an error – 463035818_is_not_a_number Jun 03 '22 at 08:13
-
Maybe https://stackoverflow.com/q/20875033/1741542 helps. This is about clang, but gcc looks similar. – Olaf Dietsche Jun 03 '22 at 08:37