1

Here i have a template class:

template <class T,int N>
 class A{
   private:
    T q;
   public:
    int show();
};

and i want to redefine func "show" different for class int, what do i do? in my thought it's like this:

template<int T,int N>
int A<int,N>::show(){

    return int(q/100);
}

how should i do it right? There are alot of examples for only one template argument,but how i do define it for two or more?

F1res
  • 118
  • 2
  • 9
  • 3
    You can't specialize only a single member of a template class. You must specialize the entire class: `template class A { // ... `. – Sam Varshavchik May 05 '18 at 00:50
  • @SamVarshavchik But i want to "redefine" method of my class, or you mean i have global missunderstanding of templates,so i need to redefine full class? – F1res May 05 '18 at 01:13
  • Yes, if you have a template class you must specialize, or "redefine" the entire class. You cannot specialize a single method. C++ does not work this way. – Sam Varshavchik May 05 '18 at 01:31
  • @SamVarshavchik: you can for **fully** specialized case, but not **partial** specialization :-/ – Jarod42 May 05 '18 at 02:01

0 Answers0