1

I have the following code of function template in C++:

class UserHelpler{

public:

   template <typename ValueType>
   void createHelper(ValueType& value);
};

template<>
void UserHelpler::createHelper<int>(int* p_user)
{
}

When I build it, it shows the following error:

error: template-id 'createHelper<int>' for 'void UserHelper::createHelper(int*)'
does not match any template declaration

What is the problem and how to fix it?

Sergey
  • 7,985
  • 4
  • 48
  • 80
ratzip
  • 1,571
  • 7
  • 28
  • 53

2 Answers2

1

The problem is that pointers and references are different things. Your template specialization has a signature which is incompatible with the template, as int* and int& are different types.

Probably, you need

createHelper<int>(int& p_user)

instead of

createHelper<int>(int* p_user)
Sergey
  • 7,985
  • 4
  • 48
  • 80
0

Your template declaration requires your parameter to be of reference type, but in your specialization you provide a pointer instead, which doesn't match. Change your specialization to:

template<>
void UserHelpler::createHelper<int>(int& p_user)

Or alternatively change your template declaration to:

template <typename ValueType>
void createHelper(ValueType* value);
Smeeheey
  • 9,906
  • 23
  • 39