I'm working on a HTTP Implementation in C++ for education purposes and I have the following classes.
Header
: Represents a Pool of HeaderFields
HeaderField
: Represents one HeaderField (Name-Value Pair)
Because many headers have multiple related values in their value (such as "Content-Type: text/plain; charset=utf-8" contains the actual content-type beside the charset wich is an additional information) I thought of my HeaderField-Class as a base-class so I can have a ContentType-Class for example which derivers from HeaderField and can only handle Content-Type-Fields. Because I can't afford to maintain all possible Header-Fields in the HTTP-Protocol I need to make this dynamic. This means, that I want to register classes which can handle some type of HeaderField and if such a HeaderField is parsed, it should be a polymorphic Object of the registered class.
I found some solution for storing a classtype here.
The problem is in the allocate()
-method:
I thought it would be nice to have the Type
- and TypeImpl
-Class as universal classes and not just for this one purpose. Therefor I need to have an Argument-List in the allocate()
-Method because some constructor-functions might need some arguments to be passed in...
This is what i tried:
class Type {
public:
virtual ~Type() {};
template<typename... Args>
virtual void* allocate(Args... args)const = 0;
...
}
template<typename T>
class TypeImpl :public Type {
public:
template<typename... Args>
void* allocate(Args... args)const {
return new T(args...);
}
...
}
This throws a Compile-Error C2898
in VS2015.
Does anyone have a workarround for this?
PS: I'm not sure whether or not va_list
can be a solution since I only found examples of extracting single arguments from it.