|
-
September 10th, 2010, 10:52 PM
#1
NOT WORK: <class T>void foo(const typename T::ENUM&)
I want a function template parameterized with a parent class, but deduced from an internal type (in this case, an enum):
class MyParent {
public:
enum MyEnum {
MY_ENUM_A,
MY_ENUM_B,
};
void foo(MyEnum my_enum) {
//...
}
static const MyParent& GetInstance(void) {
static const MyParent INSTANCE_;
return INSTANCE_;
}
};
template <class SOME_PARENT>
void SomeFunc(const typename SOME_PARENT::SOME_ENUM& some_enum)
{
SOME_PARENT::GetInstance().foo(some_enum);
}
// THE ACTUAL CALL TO USE IT:
SomeFunc(MyParent::MY_ENUM_A); // <--C2783, could not deduce template argument
SomeFunc<MyParent>(MyParent::MY_ENUM_A); // <--C2770, invalid explicit template argument
-------------------------------
Bummer ... can't I use "typename" somewhere or other bit of trickery? I realize the nested type is only an "enum" (not a real type), and I don't want to promote it to a "bigger" type with a handle to the parent class. Rather, I'd like to parameterize with the parent type, where I can use the parent type to establish a "context" to process the nested enumeration.
The goal, of course, is to merely call "SomeFunc()" with a mere enumerated value (would be so elegant if it worked ...)
Suggestions?
(sorry, can't figure out how to insert preformatted code snippets)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|