Reputation: 4505
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.
Upvotes: 3
Views: 2114
Reputation: 88711
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.Engine<void>::WorkItemResultData_ptr
.Upvotes: 4
Reputation: 82081
Since the typedef does not depend on Engine
at all, you can pull it out of the class:
typedef std::shared_ptr<WorkItemResultData> WorkItemResultData_ptr;
template <typename ExecutionPolicy>
class Engine {...};
If you want to keep it encapsulated, simply use a namespace:
namespace Engine
{
typedef std::shared_ptr<WorkItemResultData> WorkItemResultData_ptr;
}
Upvotes: 5