Thread: Overloading

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    27

    Overloading

    I know you can create a list simply with the type list provided by c++ but i need to do a list by using a vector. I think what i am asking is possible but i have no idea how to do it ..
    so far i just overloaded [] and = operators so that [] returns the value of the list in the position given and = replaces all elements in the list that are equal to number_to_replace (which is global) with the number next to = .

    Code:
    #include <iostream>
    #include <algorithm>
    #include <vector>
    
    //Global variable 
    int number_to_replace;
    
    class fifo {
    vector <int> integervector;
    
    void operator=(int replace_with){
    replace(integervector.begin(), integervector.end(), number_to_replace, replace_with);
    }
    
    int operator[](int number){
    if (integervector.size()>=number)
    return integervector[number-1];
    else 
    return -1;
    }
    };
    
    int main(){
    int list_position=0;
    
    //Making an object of type fifo
    fifo fifolist;
    
    //Is this possible with overloading ?
    //fifolist[list_position]=6
    
    return 0;
    }
    Any help will be much appreciated (again) !
    Last edited by neoragexxx; 05-01-2006 at 04:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading operators
    By ugmusicbiz in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2009, 01:41 PM
  2. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  3. overloading operator problems
    By almich in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2004, 04:10 PM
  4. operator overloading
    By blue_gene in forum C++ Programming
    Replies: 6
    Last Post: 04-29-2004, 04:06 PM
  5. overloading
    By theLukerBoy in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2002, 08:49 PM