0

I have the following class: template<typename Trait, Value> class Storage. In one application where I use this class, I want to create a synonym for Storage that "auto-fills" in the Value to be ValueA. However, as the class is used elsewhere, it doesn't make sense to have Value be set to ValueA in Storage's definition.

I've attempted to create a typedef within the header for Storage, but I keep running into compiler errors. Essentially what I'm trying to accomplish is:

template<typename trait>
typedef Storage<trait, ValueA> MyStorage<trait>;

So that I can use different traits, but have the value being stored automatically set. The error I get when I try this approach is error: template declaration of 'typedef'

Is there anyway around this limitation in C++03?

David
  • 2,080
  • 5
  • 29
  • 44

1 Answers1

0

The easiest workaround is to simply use a new class

 template<typename trait> 
 struct DefStorage : Storage<trait,ValueA> 
 {};

Technically you have to be careful because this is easily convertible to a Storage<trait,ValueA>*, and if you delete that, the destructor for DefStorage doesn't get called, which is technically undefined behavior. So be careful of that. But as long as you aren't heap allocating these, there's nothing to be concerned about.

Mooing Duck
  • 64,318
  • 19
  • 100
  • 158