c++ - 此错误会导致什么 C++ 模板问题?

标签 c++ templates compiler-errors botan

在 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

这个编译器错误告诉我什么?这是包含第 310 行的 secmem.h 片段:

[...]
/**
* 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!
[...]

最佳答案

改成这样:

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

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

如果您用 this-> 限定名称,编译器会被明确告知要查看类的范围,并在该查找中包括依赖的基类。

关于c++ - 此错误会导致什么 C++ 模板问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2841647/

相关文章:

haskell - Hackage的GenProg示例中的实例错误

c++ - 为什么在尝试使i = i * i时出现错误 “using uninitialized memory ' i'”和 “uninitialized local variable '我已使用”

ios - 由于未捕获的异常 'NSUnknownKeyException'而终止应用程序

c++ - 来自模板参数的扩展参数包(值)

c++ - 如何使用浮点值作为非类型模板参数?

c++ - 在 Visual C++ 2010 中安装 OpenCV 2.4.9 出现错误

c++ - 为什么允许泛型 lambdas 而不允许使用模板化方法的嵌套结构?

c++ - 用模板函数计算中值

c++ - C++中如何区分有理数和无理数

c++ - 无法删除 unsigned char* 数组