pLOPeGG pLOPeGG -4 years ago 54
C++ Question

Program compiling on Visual Studio 2010 but not on VS 2015

I'm working on a soft wich was written in C++ with VS 2010 a few years ago and when I want to compile it now it shows me errors. I precise that it still works if you use VS 2010 but I only have 2015 at my work.

I made a simple code to show you the error, it involves a template class tab1D that heritates from vector and redefines operators such as "()".
Here is the simplificated code incriminated :

simple main :

#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>
// //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);

When I try to compile it, it shows me errors C3867 et C2100 at the return of the operator (). But these do not seems to have any reason to pop at this moment : _Myfirst is an attribute of the vector class and it should be ok.

How can I fix this (the real file is over 3000 lines long with 600 errors, always C3867 and C2100), can I work in some sort of compatibility mode between VS 2015 and VS 2010 ?

Thank you.

EDIT : removed the conditionnal compilation

Answer Source

Your code is relying on the internal implementation details of the std::vector class, namely the _Myfirst member.

The implementation of std::vector changed between VS2010 and VS2015 such that _Myfirst was a simple pointer in VS2010 but is a member function that returns a reference to a pointer in VS2015.

You should write your code so that the tab1D class uses only the public, non-internal interface to std::vector (you might already be there with the code in the APP_LINUX blocks).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download