比方说,我们有基类表是从模板C类可能继承++专业对自己
template <typename T>
class Table
{
public:
Table();
virtual ~Table() = default;
private:
// get all column names as list
virtual std::list<std::string> getAllColumnsImpl();
};
,我想继承TestTable的类和重写方法getAllColumnsImpl从基类:
class TestTable :
public Table<TestTable>
{
public:
TestTable();
virtual ~TestTable() = default;
std::string Description;
int Count;
private:
// get all column names as list
std::list<std::string> getAllColumnsImpl() override;
};
一般情况下可以吗?
比如我有这样的链接错误:
error LNK2019: unresolved external symbol "public: __cdecl Table<class TestTable>::Table<class TestTable>(void)" ([email protected]@@@@[email protected]) referenced in function "public: __cdecl TestTable::TestTable(void)" ([email protected]@[email protected])
您不能覆盖私有成员函数,它必须被“保护”。 –
@Someprogrammerdude - 同样的错误... – Alexander
@Someprogrammerdude - Jason Lang给出的答案,这正是CRTP - 我的问题在这里有答案https://stackoverflow.com/questions/4173254/what-is-the-curiously- recurring-template-pattern-crtp - 但我之前不知道CRPT - 因为找不到有关信息 - 可能是我的问题可以帮助像我这样的人... – Alexander