GuardianX
GuardianX

Reputation: 513

Specifying one of class template argument value as any

Consider this class:

template<class T, int select>
class Foo()
{
  public:
    Foo() {}
    ~Foo() {}
    Param<select> value;
    void SomeInitialization();
    ...
}

Can I partialy specify SomeInitialization() function without explictly mentioning select value in it's template parametes list? For example I would like to merge functions realization into single one:

template<>
void Foo<SomeClass, 0>::SomeInitialization() { ... }

template<>
void Foo<SomeClass, 1>::SomeInitialization() { ... }

template<>
void Foo<SomeClass, 2>::SomeInitialization() { ... }

Into something like this (pseudocode):

template<>
void Foo<SomeClass>::SomeInitialization() { ... }

where select can be any value, since my SomeInitialization() function's code doesn't use it anyway and all functions of the above have identical code, but I have to copy paste it for every select value.

How can I achieve that? Please provide an answer using example Foo class in my post.

Upvotes: 0

Views: 88

Answers (1)

Jorge Israel Pe&#241;a
Jorge Israel Pe&#241;a

Reputation: 38576

If you take a look at this answer, it seems like all you have to do is:

template<int N>
void Foo<SomeClass, N>::SomeInitialization() { ... }

Upvotes: 1

Related Questions