перевантаження операцій
ось код моєї програми :class HugeInt
{
protected:
unsigned int count;
public:
HugeInt() :count()
{}
HugeInt ( int c):count( c )
{}
unsigned int get_count() const
{return count;}
HugeInt& operator+=(HugeInt& a)
{
return HugeInt(a+=count);
}
};
//////////////////////////////////////////////////////////
class CountDn : public HugeInt
{
public:
CountDn():HugeInt()
{}
CountDn (int c):HugeInt(c)
{}
CountDn& operator*=(CountDn& b)
{
return CountDn(b*=count);
}
};
////////////////////////////////////////////////////////
int main ()
{
CountDn *c1;
CountDn *c2;
c1=(CountDn*)malloc(sizeof(CountDn));
c2=(CountDn*)malloc(sizeof(CountDn));
//CountDn c1(256);
//CountDn c2(256);
cout<<"Enter first member fot *= "<<endl; cin>>c1;
cout<<"Enter second member for *= "<<endl; cin>>c2;
c1*=c2;
cout<<"c1"<<c1.get_count()<<endl;
HugeInt *c3;
HugeInt *c4;
c3=(HugeInt*)malloc(sizeof(HugeInt));
c4=(HugeInt*)malloc(sizeof(HugeInt));
//HugeInt c3(256);
//HugeInt c4(256);
cout<<"Enter first member fot += "<<endl; cin>>c3;
cout<<"Enter second member for += "<<endl;cin>>c4;
c3+=c4;
cout<<"c3"<<c3.get_count();
getch ();
return 0;
}
ось що вибиває:binary '+=' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
Код:
HugeInt& operator+=(HugeInt& a)
поменять на
Код:
HugeInt& operator+=(const HugeInt& a)
Код:
istream& operator>> ( istream& is, CountDn& dt )
P.S. Пишите по-русски, пожалуйста. Технические слова понятны только из контекста.
усім дякую що допомогли,все зробив!все працює!:)