I have a bunch of template parameters that I want to hide from my users. How can I do this?

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-06-17T16:44:43Z Indexed on 2010/06/17 17:03 UTC
Read the original article Hit count: 201

Filed under:
|

I have a superclass which is defined in terms of a few internal types it uses. Subclassing is performed as so:

template <class InternalType1, class InternalType2>
class Super 
{
    ...
}

class Sub : Super <interalTypeClass1, interalTypeClass2>
{ 
    ...
}

But when I want to write a function that takes a pointer to the superclass, this happens :

template <class InternalType1, class InternalType2>
void function(Super<InternalType1, InternalType2>* in) { ... }

The user really shouldn't know anything about the inside classes, and should really just concern himself with the use of the function. Some of these template lists become very very large, and expecting the user to pass them every time is wasteful, in my opinion.

Any suggestions?

EDIT: The function needs to know the internal types in use, so unless there is a way to access template types at compile time, I think there is no solution?

Potential solution: Have each class do the following:

#define SubTemplateArgs <SubTypeName, SubInternalType1, SubInternalType2>

?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates