在尝试重用不同类的代码时,我偶然发现了一个问题.我在这里发帖,希望你们中的一些人能够帮助我.
我有一组派生自同一个类(A)的类(B,C),这些类强制执行某些方法(foo,run).B类实现了这些方法,B和C都提供了其他方法:
#include<iostream>
template<class I, class O>
class A {
public:
A() {}
virtual ~A() {}
virtual void foo() const = 0; // force implementation of this function
virtual void run() const = 0; // force implementation of this function
};
template<class I, class O>
class B : public A<I,O> {
public:
B() {}
virtual ~B() {}
virtual void foo() const { // implementation for the Base class
std::cout << "B's implementation of foo" << std::endl;
}
virtual void run() …Run Code Online (Sandbox Code Playgroud)