How can I define operator==
for a nasting class?
I adds the following code for explain what I mean:
template<class T>
class TemplateClass {
int val;
public:
TemplateClass(int val) :
val(val) {
}
TemplateClass(const TemplateClass& tc) = default;
TemplateClass& operator=(const TemplateClass& tc) = default;
class Ele {
int x;
public:
Ele(int x) :
x(x) {
}
template<class S>
friend bool operator==(const Ele& e1, const Ele& e2);
};
};
template<class T>
bool operator==(const TemplateClass<T>::Ele& e1,
const TemplateClass<T>::Ele& e2) {
return e1.x == e2.x;
}
But it's not working, I get the following error:
'bool operator!=(int)' must have an argument of class or enumerated type
I will be happy to understand how can I fix it.
Aucun commentaire:
Enregistrer un commentaire