So I have this problem.
Basicly I have a templated interface:
template <typename T, typename U>
class Iinterface
{
public:
virtual ~Iinterface()
// A pure methode for the example that gives me the problem
virtual std::vector<T> myMethod(T, U) = 0;
};
No problem for now.
So I declare a class that will inherit from this interface.
class firstclass : public Iinterface<std::string, int>
{
// content doesnt matter. The problem is in second class inheritance.
// here I just put the class so we can see how I inherited in 1st class.
};
Now the myMethod decleration in the cpp file.
template <>
std::vector<std::string> firstClass::iInterface<std::string, int>::myMethod(std::string a, int b)
{
// methods code
}
So far I have no problem. It is in my second class where I declare the myMethod function and that the type T is the same as the return value that it gives me a compilation error.
class secondClass : public IInterface<std::vector<std::string>, int>
{
// class content
};
For the moment it compiles but when I declare the myMethod like this :
template <>
std::vector<std::string> secondClass::Iinterface<std::vector<std::string> a, int n>
{
// methodes code
}
Here I get an error fot the std::vector return value and the one in the methods argument.
I believe it is a template conflict but I really don’t see how to go around this.
First error:
28 :template-id ‘_out<>’ for ‘std::vector<std::basic_string<char> > Iio<std::vector<std::basic_string<char> >, int>::_out(std::vector<std::basic_string<char> >, int)’ does not match any template declaration
Second error:
28 note: saw 1 ‘template<>’, need 2 for specializing a member function template
I am still learning how to code in c++ and learn fast but once in a while I get stuck and need some help.
Is the way I am trying to do this wrong?
Do I need to declare a third typename to go around this conflict? (I was thinking it will give just an other conflict because the two typenmaes are of the same type).
I know what I am trying to do might not be the best way to do this but I am still learning.
I tryed to make example code as simple as possible to explain my problem if you need more details dont hesitate to ask.
All help will be very apriciated.
Thanks.
It seems that return value for the second class function overload should be:
What compiler are you using, gcc gave error at template specifications.