在模板類中專門化某些模板函數時,似乎前向聲明引發了一個問題。我也是爲了專門化這個功能而專門開發這個類,這似乎是導致這個問題的原因。具有前向聲明的完整類模板專業化
編輯:關於處理功能預創建功能,第二個問題:
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