0

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.

0

1 Answer 1

1

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() { ... } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank for response. But if I do so I get an error when I try to access class members inside this function - "identifier X is undefined". I use MSVS 2012.
Btw, in the link you provided he just uses float as a type, but I need to know exact value, since my Param<select> constructs parameter based on select value, not select type

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.