1
我有以下模板类,在.hpp文件中声明的.hpp文件末尾包含的.inl文件中的实现声明。 它有一个模板化的复制构造函数,但我不知道也找不到在.inl文件中实现模板化复制构造函数的正确语法。有谁知道这个正确的语法?模板类中的模板成员函数的定义(C++)
内容Foo.hpp的
template <class X>
class Foo
{
public:
explicit Foo(Bar* bar);
//I would like to move the definition of this copy ctor to the .inl file
template <class Y> explicit Foo(Foo<Y> const& other) :
mBar(other.mBar)
{
assert(dynamic_cast<X>(mBar->someObject()) != NULL);
//some more code
}
void someFunction() const;
private:
Bar* mBar;
}
#include Foo.inl
Foo.inl
template <class X>
Foo<X>::Foo(Bar* bar) :
mBar(bar)
{
//some code
}
template <class X>
Foo<X>::someFunction()
{
//do stuff
}