0
나는 인터페이스를 가지고 있으며, 템플릿 기반 클래스가이 인터페이스를 구현하도록 노력하고 있습니다. 문제를 설명하는 간단한 예는 다음과 같습니다C++ : 템플릿 클래스를 사용하여 추상 클래스 구현하기
error: templates may not be 'virtual'
virtual void Concrete<T>::do_something(int a){
이 동작을 달성 할 수있는 방법이 있나요 :
class Base{
virtual void do_something(int a) = 0;
virtual ~Base();
};
template<typename T>
class Concrete : Base{
T _t;
Concrete(T t):_t(t){};
virtual void do_something(int a);
};
template<typename T>
virtual void Concrete<T>::do_something(int a){
std::cout << a << std::endl;
}
int main(int argc, char **argv) {
Concrete<int> c;
c.do_something(5);
}
그러나 컴파일러는 불평?
함수 정의에서 virtual 키워드를 제거하십시오. 그것은이 수업 내에서 선언문을 작성하기에 충분합니다. –