A
ali_tofigh
Hi everyone,
I have a templated class with a nested class inside it. I'm trying to
define an equality operator for the nested class, one that will work
with STL-algorithms and containers. The code below shows the structure
of my program. I have tried several other approaches with no success.
Any insightful thoughts are most appreciated.
Regards,
ALiX
------------------------------------------------------------
#include <vector>
template <class T>
struct X {
T d;
struct Y {
int i;
};
};
template<class S>
bool operator==(const typename X<S>::Y &y1,
const typename X<S>::Y &y2)
{
return y1.i == y2.i;
}
int main()
{
X<double>::Y y1, y2;
y1 == y2; // this fails!
operator==<double>(y1, y2); // this works,
// but not when 'using namespace std'.
std::vector<X<double>::Y> yv1, yv2;
yv1.push_back(X<double>::Y());
yv2.push_back(X<double>::Y());
yv1 == yv2; // this fails!
return 0;
}
------------------------------------------------------------
I have a templated class with a nested class inside it. I'm trying to
define an equality operator for the nested class, one that will work
with STL-algorithms and containers. The code below shows the structure
of my program. I have tried several other approaches with no success.
Any insightful thoughts are most appreciated.
Regards,
ALiX
------------------------------------------------------------
#include <vector>
template <class T>
struct X {
T d;
struct Y {
int i;
};
};
template<class S>
bool operator==(const typename X<S>::Y &y1,
const typename X<S>::Y &y2)
{
return y1.i == y2.i;
}
int main()
{
X<double>::Y y1, y2;
y1 == y2; // this fails!
operator==<double>(y1, y2); // this works,
// but not when 'using namespace std'.
std::vector<X<double>::Y> yv1, yv2;
yv1.push_back(X<double>::Y());
yv2.push_back(X<double>::Y());
yv1 == yv2; // this fails!
return 0;
}
------------------------------------------------------------