Cryptic error on templates

Viewed 176

I am rather stumped by the error message I am seeing for a piece of code I am working on currently. I've tried to extract the most relevant pieces of the code to make it easy on the eyes.

The error I see:

error: no matching function for call to ‘Map(Print&, std::shared_ptr< LinkedList< int> >&)’
note: template argument deduction/substitution failed: cannot convert ‘p’ (type ‘Print’) to type ‘int’

Why is the compiler trying to cast Print to int at all?

template<typename T>
class LinkedList
{
public:
  using NodeType = std::shared_ptr<LinkedList>;
  ... Other things
}

template<class Func, typename T>
typename LinkedList<T>::NodeType Map(Func func, typename  LinkedList<T>::NodeType seq)
{
  // Some stuff
}

class Print
{
 public:

 int operator()(int i)
 {
     cout << i << endl;
     return i;
 }
};

void main()
{
  Print p;
  auto one = std::make_shared< LinkedList <int>> ();
  auto result = Map<int>(p, one);  << ---- Error
}

gcc 4.8.4

Thanks for reading.

2 Answers
Related