我必須編譯程序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: :字首?
嘗試更改爲'std :: size_t'? [size_t info](http://en.cppreference.com/w/cpp/types/size_t) – crashmstr
通常,用較新版本的GCC編譯一個較舊的程序應該不是問題(反之亦然更難)。從你的錯誤看來'size_t'是未知的。對於較新的版本,它應該是'std :: size_t'。你可以嘗試爲它定義一個typedef。 –
是的,所有的錯誤都是由於缺少包含或(像crashmstr寫)缺少std ::前綴。在舊版本中,不需要添加std :: ??如何在不使用std ::或include的舊版gcc中工作? – Karlvonbahnhof