【问题标题】:What C++ templates issue is going on with this error?这个错误发生了什么 C++ 模板问题?
【发布时间】:2010-05-15 20:30:44
【问题描述】:

在 Botan v1.8.8 上运行 gcc v3.4.6 在成功构建 Botan 并运行其自检后,在构建我的应用程序时出现以下编译时错误:

../../src/Botan-1.8.8/build/include/botan/secmem.h: In member function `Botan::MemoryVector<T>& Botan::MemoryVector<T>::operator=(const Botan::MemoryRegion<T>&)':
../../src/Botan-1.8.8/build/include/botan/secmem.h:310: error: missing template arguments before '(' token

这个编译器错误告诉我什么?这是 secmem.h 的 sn-p,其中包括第 310 行:

[...]
/**
* This class represents variable length buffers that do not
* make use of memory locking.
*/
template<typename T>
class MemoryVector : public MemoryRegion<T>
   {
   public:
      /**
      * Copy the contents of another buffer into this buffer.
      * @param in the buffer to copy the contents from
      * @return a reference to *this
      */
      MemoryVector<T>& operator=(const MemoryRegion<T>& in)
         { if(this != &in) set(in); return (*this); }  // This is line 310!
[...]

【问题讨论】:

  • @Clever -1er:你刚刚给了他 8 分,因为他没有解释你的问题。
  • @sepp2k: 是的——我暂时忘记了...

标签: c++ templates compiler-errors botan


【解决方案1】:

改成这样:

{ if(this != &in) this->set(in); return (*this); } 

我怀疑set 函数是在基类中定义的?未在依赖于模板参数的基类中查找非限定名称。所以在这种情况下,名称set 可能与需要模板参数的std::set 模板相关联。

如果您使用this-&gt; 限定名称,编译器会被明确告知查看类的范围,并在该查找中包含相关的基类。

【讨论】:

  • 该死的,约翰内斯!我以为你是学生?!周六晚上你难道不想做其他事情,然后从老人那里获得代表点数吗?无论如何:) +1 来自我。
  • @sbi 我不太适合派对 :)
  • 聚会是一件事,只需不到 10,000 小时即可掌握。
  • 好吧,我同意 Wilhelm 的意见。 (而且,FWIW,我认为 Giessen 也不是那么适合派对。BICBW。)无论如何,如果你碰巧来到这里(见个人资料),给我一个提示,你会被邀请喝一杯免费啤酒一个脾气暴躁的老人。 :)
  • @Wilhelm 哦,可怜的书呆子 litb 需要的远不止这些
猜你喜欢
  • 1970-01-01
  • 2012-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多