hello all I'm yet again stumped by the programming jargon used by my book. The question I have is what do they mean when they say that they are overloading an assignment operator thank you very kindly. I appreciate any feedback thanx.
hello all I'm yet again stumped by the programming jargon used by my book. The question I have is what do they mean when they say that they are overloading an assignment operator thank you very kindly. I appreciate any feedback thanx.
i think i might know what you mean. I may also make you want to smash your head on a rock for not understanding what you mean . Overloading in my (mental) book goes something like follows:
(a function in a class or something)
doSomething(int i, float f) //this is normal
{
(code for doing something with i and f)
}
doSomething(float i, float f, int t) //This is overloading the doSomething function)
{
(code for doing something with i, f, and t)
}
//in other words, overloading means creating a function made for certain parameters, and then making another function WITH THE SAME NAME, but different parameters.
whoa take it easy there cowboy here is what I mean
everytime I run this bit of code I get a funky error message sayingCode:#include <iostream.h> #include <iomanip.h> class Car { private: char bodystyle[5]; int colorcode; int engsize; public: Car(char[5]="xxxxx",int=0, int=0); //constructor function with defaults cartype(char,int, int); //member function to copy car info void showcar(void); }; //implementation section Car::cartype(char bod[5], int code, int eng) { bodystyle[5]=bod[5]; colorcode=code; engsize=eng; } void Car::showcar(void) { int enginesize; cout<<"The car is"; cout<< setfill('0') <<setw(2) << bodystyle << ":" <<setw(2) << colorcode << ":" <<setw(2) << enginesize ; cout<<endl; return; } int main() { Car a, c("xxxxx", 2 , 1); cout<<endl; a.showcar(); c.showcar(); cout<<endl; return 0; }
overloaded member function 'int (char [],int,int)' not found in 'Car'
I just need to know where I've gone wrong any help would be much
appreciated
no clue... sorry
That's overloading a function.Originally Posted by Neonpricetag
Overloading an operator is different. And something which I still need to learn.
i realized my error when he posted the code, but prehaps you need to put
Car a("xxxxx", 2 , 1), c("xxxxx", 2 , 1);
but then again, my brain has been muddled up in C++ since learning java, which i am still confused about the reasons for learning it (java's speed < snails)
Code://implementation section Car::cartype(char bod[5], int code, int eng) { bodystyle[5]=bod[5]; colorcode=code; engsize=eng; }
1. Is this suppose to be your constructor definition? Your class name is Car and not cartype.
2. if it is not the constructor, it should have the return type.
3. i dont think "bodystyle[5] = bod[5]" will do what u want