1

I'm trying to make a generic class that receives, as paramater, a vector of generic types. That's is my goal.

This is what i have in header file:

#pragma once
#include <vector>
#include "iostream"
using namespace std;
class Permutation
{
public:
       template<class T>
       //I already tried that
       //template< typename T>
    static unsigned int generate(std::vector<T> source, bool recursive = false);
    };
}

Until now i receive the same error "Unresolved Externals.

How can i correct implement that?

Note: the implementation of code is in CPP file

Leandro
  • 114
  • 2
  • 10
  • "Note: the implementation of code is in CPP file". And, that's your problem. – Sam Varshavchik Feb 28 '17 at 00:25
  • Generally speaking templates need to be implemented in the header file, not the cpp. The simplest way to start would probably just be for you to implement it inline. Your code also has an extra curly brace. Please post a *full* example of the code that duplicates the problem in general when posting on SO. – Nir Friedman Feb 28 '17 at 00:25
  • I already have the implementation of template in header file. I can replicate de template to cpp file? I need to implement all code in the header file? I already try that but unfortunately gives me the same error – Leandro Feb 28 '17 at 00:33
  • @Leandro no. Templates must be in the header *only* if you don't know it will be used with what type in advance. If you know all the cases in advance, you can use extern template, but I wouldn't recommend it. – Guillaume Racicot Feb 28 '17 at 01:07

0 Answers0