在模板类中专门化某些模板函数时,似乎前向声明引发了一个问题。我也是为了专门化这个功能而专门开发这个类,这似乎是导致这个问题的原因。具有前向声明的完整类模板专业化
编辑:关于处理功能预创建功能,第二个问题:
processor.H
namespace OM{
template<typename MatchT> //fwd decl. ERROR 2. see below.
class Manager;
template<typename MatchT>
class Processor
{
public:
Processor(Manager<MatchT>& mgr_):_manager(mgr_) {}
template<int P>
void process();
void doProcess();
private:
Manager<MatchT>& _manager;
template<int P, int... Ps>
struct table : table<P-1,P-1, Ps... > {};
template<int... Ps>
struct table<0, Ps...>
{
static constexpr void(*tns[])() = {process<Ps>...};
};
static table<5> _table;
};
}
#include "processor.C"
processor.C
namespace OM{
#include "MyManager.H" (includes MyManager/MyConfig)
template<typename MatchT>
template<int P>
inline void Processor<MatchT>::process()
{
...
_manager.send(); //this works..
}
template <> template <>
inline void Processor<MyManager<MyConfig> >::process<1>()
{
_manager.send(); //ERROR 1 - see below.
}
//ERROR here:
template<typename MatchT>
void doProcess()
{
Processor<MatchT>::_table::tns[2](); ERROR 3 below.
}
}
编译错误:
1. error: invalid use of incomplete type 'class Manager <MyManager<MyConfig> >'
2. error: declaration of 'class Manager<MyManager<MyConfig> >'
class Manager;
3. error: no type name '_table' in "class Processor<MyManager<MyConfig> >'
I'm not calling this from a specialized function, so I'm not sure
why I'm getting this.
我可以移动一些东西以确保_manager调用不在专用函数内,但是如果我不需要,我宁愿不要。
'namespace OM {.. #include“MyManager.H”'所以当这个头文件被包含时,最终代码中将会包含'namespace OM {namespace OM {'' –
'//这工作..'它可能实际上并没有,它只是没有被实例化。 – user657267
Maanger在同一翻译单元的另一个文件中定义。 – ggs