Help on operator overloading

This is a discussion on Help on operator overloading within the C++ Programming forums, part of the General Programming Boards category; I'm trying to make my own text based racing sim but when I try to display the cars details I ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    Help on operator overloading

    I'm trying to make my own text based racing sim
    but when I try to display the cars details I get an error.

    I need to overload the operator << can someone help with that?
    I tried several things but it just won't work

    this is the error:
    error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)


    Code:
    void Car::details()
    {
    	int damage = m_Damage;
    	int gas = m_Gas;
    	int speed = m_Speed;
    	int engine = m_Engine;
    
    	cout << "Car details: \n";
    	cout << "Max Speed: " << speed << endl;
    	cout << "Gas Level: " << gas << endl;
    	cout << "Damage Level: " << damage << endl;
    	cout << "Engine Power: " << engine << endl;
    }
    
    
    int main()
    {
    	Car myCar;
    
    	cout << myCar.details(); // this gives the problem
    
    	return 0;
    }

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    307
    Code:
    void Car::details()
    It's void!!!!!
    Try:
    Code:
    int main()
    {
    	Car myCar;
    
    	myCar.details(); // ???
    
    	return 0;
    }
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    2
    thanks that was the problem

    a bit of a stupid fault :P

Popular pages Recent additions subscribe to a feed

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