Thread: overloading binary + operator

  1. #1
    Unregistered
    Guest

    overloading binary + operator

    I need some help or a suggestion please

    I have a template class in which I am trying to implement the following:

    myClass + 'any type variable';

    where 'any type variable' lets say for this example is '10' is added to a private member vector (called temp) in myClass

    So say before the vector was 5,7,8 the (+ 10) would just add 10 to the end of the vector so it would now have 5,7,8,10

    I also need to be able to chain the operation so
    myClass + 10 + 11 + 12; would result in:
    5,7,8,10,11,12

    Code:
    template<typename T>
    myClass<T> operator + (***WHAT GOES HERE**)  	
    {
    	temp.push_back( **WHAT GOES HERE**);		
    	return *this;	
    
    }

    any help would be appreciated

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    Code:
    template<typename T>
    myClass<T> operator + (T item)	
    {
    	temp.push_back( item);		
    	return *this;	
    
    }
    or something like that depending on what temp.push_back does

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  2. Operator overloading question
    By 39ster in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2007, 12:26 PM
  3. Operator Overloading
    By supaben34 in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2003, 11:29 PM
  4. Operator overloading MSVC++
    By AeroHammer in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 01:40 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM