Mar 10, 2012 at 5:06pm Mar 10, 2012 at 5:06pm UTC
i don't really know about this too, but as far as i know, the overloaded functions is not your class' member function, it should be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class MyClass
{
public :
MyClass() : varI(0),varF(0) {}
MyClass(int i,float f): varI(i),varF(f) {}
int getVarI() { return varI; }
float getVarF() { return varF; }
void setVarI(int i) {varI=i;}
void setVarF(float f) {varF=f;}
friend istream& operator >> (istream & input, MyClass& o);
private :
int varI;
float varF;
};
Last edited on Mar 10, 2012 at 5:07pm Mar 10, 2012 at 5:07pm UTC
Mar 10, 2012 at 5:21pm Mar 10, 2012 at 5:21pm UTC
Thanks,with friend and accessint the variables directly work
Is there way to set the variables with set functions
Mar 14, 2012 at 7:55pm Mar 14, 2012 at 7:55pm UTC
Thanks,with friend and accessint the variables directly work
Is there way to set the variables with set functions
1 2 3 4 5 6 7 8 9
istream& operator >>(istream &input,MyClass &o)
{
int i ;
float f ;
input >> i >> f;
o.setVarI(i) ;
o.setVar(f) ;
return input;
}
Last edited on Mar 14, 2012 at 7:56pm Mar 14, 2012 at 7:56pm UTC
Mar 14, 2012 at 10:07pm Mar 14, 2012 at 10:07pm UTC
cin is not an operator, it's an object of class istream. You would need to overload the >> operator