2013-11-26 61 views
0

我必須編譯程序probcons但有很多錯誤。在自述文件中,寫入程序與gcc 4.3兼容,但我只有4.7.2。有什麼辦法可以編譯這個舊程序嗎?我不相信在程序中是錯誤的,因爲許多生物信息學服務器正在使用它。爲舊的gcc編譯程序

最奇怪的是我這個錯誤:

Description     Resource   Path  Location Type 

expected ‘)’ before ‘size’ SafeVector.h /probcons line 27 C/C++ Problem 
expected ‘)’ before ‘size’ SafeVector.h /probcons line 26 C/C++ Problem 

在課堂SafeVector.h:

///////////////////////////////////////////////////////////////// 
// SafeVector.h 
// 
// STL vector with array bounds checking. To enable bounds 
// checking, #define ENABLE_CHECKS. 
///////////////////////////////////////////////////////////////// 

#ifndef SAFEVECTOR_H 
#define SAFEVECTOR_H 

#include <cassert> 
#include <vector> 

///////////////////////////////////////////////////////////////// 
// SafeVector 
// 
// Class derived from the STL std::vector for bounds checking. 
///////////////////////////////////////////////////////////////// 

template<class TYPE> 
class SafeVector : public std::vector<TYPE>{ 
public: 

    // miscellaneous constructors 
    SafeVector() : std::vector<TYPE>() {} 
    /*ERROR HERE*/ SafeVector(size_t size) : std::vector<TYPE>(size) {} 
    /*ERROR HERE*/ SafeVector(size_t size, const TYPE &value) : std::vector<TYPE>(size, value) {} 
    SafeVector(const SafeVector &source) : std::vector<TYPE>(source) {} 

#ifdef ENABLE_CHECKS 

    // [] array bounds checking 
    TYPE &operator[](int index){ 
    assert (index >= 0 && index < (int) size()); 
    return std::vector<TYPE>::operator[] ((size_t) index); 
    } 

    // [] const array bounds checking 
    const TYPE &operator[] (int index) const { 
    assert (index >= 0 && index < (int) size()); 
    return std::vector<TYPE>::operator[] ((size_t) index) ; 
    } 

#endif 

}; 

它是如何可能的是,在舊版本的gcc沒有需要包括和std: :字首?

+6

嘗試更改爲'std :: size_t'? [size_t info](http://en.cppreference.com/w/cpp/types/size_t) – crashmstr

+0

通常,用較新版本的GCC編譯一個較舊的程序應該不是問題(反之亦然更難)。從你的錯誤看來'size_t'是未知的。對於較新的版本,它應該是'std :: size_t'。你可以嘗試爲它定義一個typedef。 –

+0

是的,所有的錯誤都是由於缺少包含或(像crashmstr寫)缺少std ::前綴。在舊版本中,不需要添加std :: ??如何在不使用std ::或include的舊版gcc中工作? – Karlvonbahnhof

回答

0

嘗試specifying the language standard對於gcc。我建議你試試

-std=g++11 

首先,我覺得最有可能編譯它。如果不起作用,請嘗試其他選擇。

如何添加這取決於編譯如何完成,但一個「快速&髒」的方式是添加這是找到生成文件,找到一行指定編譯器標誌變量CXXFLAGS並將其添加到它。注意:如果它是生成的生成文件,如果再次運行生成器,編輯會被覆蓋。

+0

不幸的是,我嘗試了所有-std = C++的可能性,但沒有任何工作。只添加std ::前綴和一些#include。 – Karlvonbahnhof