First, a tiny example demonstrating the problem:
struct Bar {
enum Baz {aa, bb, cc};
Baz baz_;
operator Baz() const { return baz_; }
private:
template<typename T> operator T() const;
};
int main() {
Bar bar;
switch (bar) {
case Bar::aa:
break;
case Bar::bb:
break;
case Bar::cc:
break;
default:
break;
}
return 0;
}
Compiling this code with g ++ 4.7.0 gives the following error:
foo.cpp: In function ‘int main()’:
foo.cpp:12:16: error: ambiguous default type conversion from ‘Bar’
foo.cpp:12:16: error: candidate conversions include ‘template<class T> Bar::operator T() const’
I understand that since the struct object is "enabled", the compiler will try to find the conversion function for an integer or enumerated type. I explicitly provide a public function to convert to the enum type Bar :: Baz and would like to use it.
, , , . ? , switch((int)bar), , , , . , , ?
, ( 100%) g++ 4.6.
edit: , , .