Template class typedef - use outside of class
c++, templates, visual-studio-2010
Solution
Is there a way to use type `Engine::WorkItemResultData_ptr` outside of Engine class ?
Yes, but you'll need to say `typename` if it's in a template context, e.g.:
template <typename T>
void foo() {
typename Engine<T>::WorkItemResultData_ptr instance;
}
You can't access that `typedef` without a type. There are three workarounds possible though:
- `typedef` outside the template! - it's likely it doesn't have much to do with the template if it doesn't depend on the types.
- Use a bodge and refer to `Engine<void>::WorkItemResultData_ptr`.
- Have a non-template base class which contains the typedef and inherit from that. You can access the non-template base class fine then.
Problem
I have a class like this: ``` struct WorkItemResultData; template <typename ExecutionPolicy> class Engine { public: typedef std::shared_ptr<WorkItemResultData> WorkItemResultData_ptr; } ``` `typedef` does not depend on any template argument. Is there a way to use type `Engine::WorkItemResultData_ptr` outside of `Engine` class ? EDIT I know I could use it like awoodland proposed the solution bellow but my typedef is independent of type arguments and want to be able to do it without specifying a specific Engine type.