尝试编译MixKit库时出错(C ++)

时间:2014-12-10 23:40:01

标签: c++ templates memory compiler-errors header-files

我正在尝试编译一些古代代码(最后更新2004)。

我收到一些错误消息,我已经指出了代码位置和下面的错误。

1

https://code.google.com/p/hmeshsimp/source/browse/trunk/hsimpkit/MixKit/MxDynBlock.h?r=71#40

MxDynBlock.h:38:31: error: there are no arguments to ‘resize’ that 
depend on a template parameter, so a declaration of ‘resize’ must be 
available [-fpermissive] ... 

  if( length()<len ) resize(len);

2

https://code.google.com/p/hmeshsimp/source/browse/trunk/hsimpkit/MixKit/MxDynBlock.h?r=71#67

MxDynBlock.h:66:68: error: there are no arguments to ‘begin’ that 
depend on a template parameter, so  a declaration of ‘begin’ must 
be available [-fpermissive] ... 

我认为需要包含正确的标头,但我无法找到哪一个。你能帮我吗?

1 个答案:

答案 0 :(得分:1)

您必须使用this->begin()this->resize()

此语言功能的最小演示如下:

template <typename T>
struct foo
{
    void bar() {}
};

template <typename T>
struct baz : foo <T>
{
    void qux() { 
      bar();         // <- bad
      this->bar();   // <- good
    }
};

原因是虽然foo<T>bar<T>的基类,但编译器无法确定bar你的意思是foo<T>::bar。如果您对foo进行专门化以使其没有bar该怎么办?你需要明确告诉它&#34;是的,我想那个 bar&#34;。

该功能称为&#34;两阶段名称查找&#34;,它是C ++标准的旧功能。 More info on stackoverflow