我是C ++类模板的新手。我在这里做什么错了?
scrollbars.h
文件:
namespace Scrollbars
{
template <typename T>
class CScrollbars : public T
{
public:
CScrollbars();
~CScrollbars();
};
};
scrollbars.cpp
文件:
#include "Scrollbars.h"
namespace Scrollbars
{
template<class T>
CScrollbars<T>::CScrollbars()
{
//Constructor
}
template<class T>
CScrollbars<T>::~CScrollbars()
{
//Destructor
}
};
上面的所有模板都是这样,因此我可以从其他各种类派生它们的基类。例如,在下面的类中,我希望CFancyEdit
从CScrollbars
派生,而CRichEditCtrl
又从任意类派生,在这种情况下为FancyEdit.h
,但可以是任何其他类:
namespace FancyEdit
{
using namespace Scrollbars;
//Derive it from the MFC class CRichEditCtrl
class CFancyEdit : public CScrollbars<CRichEditCtrl>
{
public:
CFancyEdit();
~CFancyEdit();
};
};
文件:
FancyEdit.cpp
#include "FancyEdit.h"
namespace FancyEdit
{
CFancyEdit::CFancyEdit()
{
//Constructor
}
CFancyEdit::~CFancyEdit()
{
//Destructor
}
};
文件:
1>FancyEdit.obj : error LNK2019: unresolved external symbol "public: __cdecl Scrollbars::CScrollbars<class CFancyEdit>::CScrollbars<class CFancyEdit>(void)" referenced in function "public: __cdecl FancyEdit::CFancyEdit::CFancyEdit(void)"
1>FancyEdit.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl Scrollbars::CScrollbars<class CFancyEdit>::~CFancyEdit<class CFancyEdit>(void)" referenced in function "int `public: __cdecl FancyEdit::CFancyEdit::CFancyEdit(void)'::`1'::dtor$0"
它可以编译,但是会给我这些链接器错误:
parent: {
id: Schema.Object,
title: String,
children: []
}