我有一個調試類,我在我的代碼中使用打印各種東西。在這個類中,我重載operator()
以方便輸出。我有幾個operator()
打印載體。當我添加模板版本時,我遇到了編譯錯誤。任何矢量打印內容
下面是代碼:
template<class Type1>
inline debug&
operator()(const std::string& name,
typename std::vector<Type1>::const_iterator begin,
typename std::vector<Type1>::const_iterator end)
{
_stream << indent(internal) << "< " << name << " : [ ";
std::copy(begin, end, std::ostream_iterator<Type1>(_stream, " "));
_stream << "] >" << std::endl;
return *this;
}
而另一矢量打印功能,我有:
inline debug&
operator()(const std::string& name,
typename std::vector<uint32_t>::const_iterator begin,
typename std::vector<uint32_t>::const_iterator end)
{
_stream << indent(internal) << "< " << name << " : [ " << std::hex;
std::copy(begin, end, std::ostream_iterator<uint32_t>(_stream, " "));
_stream << "] >" << std::endl;
return *this;
}
凡indent()
不正是它說。
這裏是編譯錯誤:
../include/debug.hh:146:3: note: template<class Type1> relix::debug& relix::debug::operator()(const string&, typename std::vector<_RealType>::const_iterator, typename std::vector<_RealType>::const_iterator)
../include/debug.hh:146:3: note: template argument deduction/substitution failed:
assembler.cc:78:64: note: couldn't deduce template parameter ‘Type1’
這裏是assembler.cc:78:
log(D_C(tl._tokens), tl._tokens.begin(), tl._tokens.end());
凡D_C()
是取代預處理宏提取變量的名稱和_tokens
是的std::vector
token
,其中token
有一個超載operator<<()
。
請創建演示問題的儘可能小的程序,然後在您的問題中複製粘貼整個程序。 http://sscce.org/。 – 2012-02-27 15:01:12