can anyone tell me how can i make the following code to work fine in MVS and GNU compiler? This code will work only for MVS. GNU compiler will generate a building error.
Code:
#include <iostream>
#include <vector>
using namespace std;
template<class T>
const vector<T>&
operator*=(vector<T>& obj1, const T typeVal)
{
for (unsigned i = 0; i < obj1.size(); i++)
obj1[i] *= typeVal;
return obj1;
}
template<class T>
const vector<T>
operator*(const vector<T>& obj1, const T typeVal)
{
return (vector<T>(obj1) *= typeVal);
}
template<class T>
const vector<T>
operator*(const T typeVal, const vector<T>& obj1)
{
return (obj1*typeVal);
}
int main()
{
vector<double> x(3,4);
vector<double> d = x*2.0;
cout << d[0] << " " << d[1] << " " << d[2] << endl;
return 0;
}

