在 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/