[英]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.