overloading an operator

This is a discussion on overloading an operator within the C++ Programming forums, part of the General Programming Boards category; hello all I'm yet again stumped by the programming jargon used by my book. The question I have is what ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    overloading an operator

    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.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    5
    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.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    78
    whoa take it easy there cowboy here is what I mean
    Code:
    #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;
    }
    everytime I run this bit of code I get a funky error message saying
    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

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    5
    no clue... sorry

  5. #5
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Quote Originally Posted by Neonpricetag
    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.
    That's overloading a function.

    Overloading an operator is different. And something which I still need to learn.

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    5
    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)

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  4. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 01:55 PM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 12:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21