2014-12-10 140 views
1

我想編譯一些古代碼(最後更新2004年)。嘗試編譯MixKit庫時出錯(C++)

我收到了幾條錯誤消息,我指出了代碼位置和下面的錯誤。

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

您必須使用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,該怎麼辦?你需要明確地告訴它「是的,我想要bar」。

該功能被稱爲「兩階段名稱查找」,它是C++標準的一箇舊功能。 More info on stackoverflow

+0

感謝您的提示,早些時候我按照指示使用了「超寬容」,但這樣更乾淨。再次感謝! – jason 2014-12-12 21:03:36