[英]Compiling VC++ program with Npcap in Visual Studio 2015
[英]Program compiling on Visual Studio 2010 but not on VS 2015
我正在研究幾年前用VS 2010用C ++編寫的軟件,現在我想編譯它時會顯示錯誤。 我精確地說,如果您使用VS 2010,它仍然可以工作,但我只有2015年。
我編寫了一個簡單的代碼向您展示該錯誤,它涉及一個模板類tab1D,該類繼承自vector並且重新定義了運算符,例如“()”。 這是簡化的代碼:
簡單的主要:
#include <iostream>
#include "memory_tab.h"
using namespace std;
int main() {
cout << "Hello" << endl;
tab1D<int> t (2);
cout << "Initialization works fine" << endl;
cout << t[1] << endl;
cout << "Bracket operator works fine" << endl;
cout << t(1) << endl; // this line calls parenthesis operator which is overwritten in memory_tab.h. It does not compile.
cout << "Error C3867 & C2100" << endl;
int a;
cin >> a;
return 0;
}
memory_tab.h:
//includes and stuff
template <class T>
class tab1D : public vector<T>
{
public:
// //Constructors
// /*!
// * \brief Default constructor (set nbElem and tailleMem to 0)
// */
tab1D() : vector<T>() {};
tab1D(int _nbElem) : vector<T>(_nbElem) {}; // set all elements to 0
// //Operators
T& operator() (unsigned val);
T& operator() (unsigned val) const;
};
template <class T> T& tab1D<T>::operator() (unsigned val)
{
return *(_Myfirst + val);
}
template <class T> T& tab1D<T>::operator() (unsigned val) const
{
return *(_Myfirst + val);
}
當我嘗試編譯它時,它在操作符()返回時向我顯示錯誤C3867和C2100 。 但是這些似乎目前沒有任何理由彈出:_Myfirst是向量類的屬性,應該沒問題。
如何解決此問題(實際文件超過3000行,出現600個錯誤,始終為C3867和C2100),我可以在VS 2015和VS 2010之間以某種兼容模式工作嗎?
謝謝。
您的代碼依賴於std::vector
類(即_Myfirst
成員)的內部實現細節。
在VS2010和VS2015之間更改了std::vector
的實現,因此_Myfirst
是VS2010中的簡單指針,但是一個成員函數,該成員函數返回對VS2015中的指針的引用。
您應該編寫代碼,以便tab1D
類僅使用公共的非內部接口連接std::vector
( APP_LINUX
塊中的代碼可能已經存在)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.