I have tried variations of const and passing by reference, but seem to have problems down every corridor. This configuration gives the error cannot bind non-const lvalue reference of type ‘thingArr&’ to an rvalue of type ‘thingArr’ what am I doing incorrectly?
#include <iostream>
using namespace std;
template <typename T>
class thingArr
{
public:
thingArr(){for(int i=0;i<4;++i)n[i] = 1;}
thingArr(thingArr& mIn){for(int i=0; i<4; ++i)n[i]=mIn.n[i];}
friend std::ostream& operator << (std::ostream& s, thingArr<T>& m)
{
s<<"\n("<<m.n[0]<<", "<<m.n[1]<<", "<<m.n[2]<<", "<<m.n[3]<<")";
return s;
}
friend thingArr operator * (thingArr inThingArr, T inScalar)
{
thingArr out(inThingArr);
for(int i=0;i<4;++i)out.n[i]*=inScalar;
return thingArr(out);
}
T n[4];
};
main(){
thingArr<float> A;
thingArr<float> B;
B = A * .25;
cout <<"A: "<<A<<endl;
cout <<"B: "<<B<<endl;
}