그래서이 문제가 있습니다. 지금은C++ 템플릿 인터페이스에서 다중 상속
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;
};
없음 문제 :
Basicly은 내가 템플릿 인터페이스를 가지고있다. 그래서이 인터페이스에서 상속받을 클래스를 선언합니다.
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.
};
이제는 cpp 파일의 myMethod 암호를 해독합니다.
template <>
std::vector<std::string> firstClass::iInterface<std::string, int>::myMethod(std::string a, int b)
{
// methods code
}
지금까지 아무런 문제가 없습니다. 두 번째 클래스에서 myMethod 함수를 선언하고 T 유형은 반환 값과 동일하므로 컴파일 오류가 발생합니다. 이 컴파일 순간
class secondClass : public IInterface<std::vector<std::string>, int>
{
// class content
};
하지만이 같은 MyMethod라는를 선언 할 때 :
template <>
std::vector<std::string> secondClass::Iinterface<std::vector<std::string> a, int n>
{
// methodes code
}
을 여기에 나는 표준 : : 벡터 반환 값 FOT 오류 및 방법 인자의 하나를 얻을. 템플릿 충돌이라고 생각하지만 실제로이 문제를 해결하는 방법을 모르겠습니다.
첫 번째 오류 :
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
두 번째 오류 : 난 여전히 C 코드 ++ 빠르게 배울 수 있지만, 한 번에 한 동안 나는 박히면서 어떤 도움을 필요로하는 방법을 배우고
28 note: saw 1 ‘template<>’, need 2 for specializing a member function template
. 내가 잘못하려는 방식입니까? 이 충돌을 피하기 위해 세 번째 typename을 선언해야합니까? (나는 두 개의 typenmaes가 같은 유형이기 때문에 다른 충돌을 줄 것이라고 생각했다.)
내가하는 일은 최선의 방법이 아닐지 모르지만 나는 여전히 배우고있다.
자세한 내용이 필요하면 주저하지 말고 가능한 한 간단하게 예제 코드를 작성해보십시오.
모든 도움말은 매우 복잡해집니다. 감사합니다. .
감사합니다. 나는 그렇게 보지 못했습니다. 나는 바보입니다. 벡터로 실습 할 때 나는 정말로 carfull이되어야한다. ^^ – Jp1987
자신이 호의를 베푼다. 클래스 템플릿에서 물건을 typedef'ing하면, 이렇게 못생긴 표정을 피할 수있다. – bstamour
조언 해 주셔서 감사합니다. 나는 기본적으로 테스트를 위해 이와 같은 작업을하고 있으며 어떻게 작동 하는지를 exacly 살펴보기 위해 학습하고 있습니다. – Jp1987