Thread: Overloading << and >>

  1. #1
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282

    Overloading << and >>

    I am trying to overload the << and >>.
    It was really easy with the +,-,*,/..but to be honest I am drawing a total blank with what to do/how to do the << and >>

    Here is my class:
    class SalesFigures
    Code:
    {
    	
    	public:
    
    
    		friend SalesFigures operator +(const SalesFigures& value1, const SalesFigures& value2);
    		friend SalesFigures operator -(const SalesFigures& value1, const SalesFigures& value2);
    		friend SalesFigures operator *(const SalesFigures& value1, const SalesFigures& value2);
    		friend SalesFigures operator /(const SalesFigures& value1, const SalesFigures& value2);
    
    		//friend ostream& operator <<(ostream& in, SalesFigures& temp);
    
    
    		SalesFigures(double jan, double feb, double march_);
    		//Initializes private member variables to whatever is passed.
    		SalesFigures();
    		//Default constructor, initializes private member variables to zero.
    
    
    		double get_month_sales(int select);
    		/*Returns value for private member variables.
    		Passing '1' returns January, Passing '2' returns February, passing '3' returns March.
    		Attempt to pass anyother integer value will result in error message and program to exit.*/
    
    
    		void output(ostream& out);
    		/*Outputs Data.
    		If outputing to a file, file stream must already be connected.*/
    
    
    	private:
    
    		double January;
    		double February;
    		double March;
    
    
    };

    Any tips on where/how to start/what to do would be greatly appericated!
    Last edited by Enahs; 09-15-2005 at 04:30 PM.

  2. #2

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Ohh wow thanks.
    I am a total tard.

    I was trying to some how with return use "=" instead of the actual operator.


    *hangs head in shame*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading << and >>
    By MMu in forum C++ Programming
    Replies: 1
    Last Post: 04-21-2008, 06:49 AM
  2. Overloading fstream's << and >> operators
    By VirtualAce in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 03:17 AM
  3. << and >> overloading
    By Armatura in forum C++ Programming
    Replies: 2
    Last Post: 12-07-2003, 06:19 PM
  4. Overloading the << and >> operators
    By WebmasterMattD in forum C++ Programming
    Replies: 9
    Last Post: 10-15-2002, 05:22 PM
  5. istream >> overloading
    By wazza13 in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2002, 10:56 PM