D
Doctor Smith
Hello!
I would like to have an output streaming operator for an enum that is
inside a templated class, but I just can't seem to make it work! I
suspect that I have a template ambiguity issue, but I haven't pinned
down what change will make the code work.
The following example illustrates the problem. I would like the
program to print 'C', but it prints '2'.
#include <iostream>
template <typename AX_FLOAT>
class M
{
public:
enum T
{
A,
B,
C
};
};
template <typename AX_FLOAT>
std:stream& operator<<(std:stream& os, typename M<AX_FLOAT>::T t)
{
switch (t)
{
case M<AX_FLOAT>::A: os << 'A'; break;
case M<AX_FLOAT>::B: os << 'B'; break;
case M<AX_FLOAT>::C: os << 'C'; break;
}
return os;
}
int main()
{
M<float>::T t = M<float>::C;
std::cout << "t = " << t << std::endl;
}
Any insights on how to make this work, or why it will never work, is
muchly appreciated.
I would like to have an output streaming operator for an enum that is
inside a templated class, but I just can't seem to make it work! I
suspect that I have a template ambiguity issue, but I haven't pinned
down what change will make the code work.
The following example illustrates the problem. I would like the
program to print 'C', but it prints '2'.
#include <iostream>
template <typename AX_FLOAT>
class M
{
public:
enum T
{
A,
B,
C
};
};
template <typename AX_FLOAT>
std:stream& operator<<(std:stream& os, typename M<AX_FLOAT>::T t)
{
switch (t)
{
case M<AX_FLOAT>::A: os << 'A'; break;
case M<AX_FLOAT>::B: os << 'B'; break;
case M<AX_FLOAT>::C: os << 'C'; break;
}
return os;
}
int main()
{
M<float>::T t = M<float>::C;
std::cout << "t = " << t << std::endl;
}
Any insights on how to make this work, or why it will never work, is
muchly appreciated.