Thread: Operloading operators w/templates

  1. #1
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49

    Operloading operators w/templates

    Hi guys
    Im trying to overload the [] operator so I can read and write into an object.
    Ex.
    Code:
    Arrray_class <int> age;
    
    age["Bob"]=30;
    I dont know the syntax for overloading user defined template classes
    I tried this...
    Code:
    template<class T>
    void  &Array_class< T > ::operator[]();
    {
    
    }
    But that doesnt work. Any ideas?

    Thanks

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Try this:
    Code:
    template<class T>
    T& Array_class< T > ::operator[](int index);
    {
    
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    82
    what happens if you have a const Array_class?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Operators in C++
    By Flecto in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2009, 07:17 AM
  2. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  3. operators???
    By arjunajay in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2005, 04:37 AM
  4. Overloading compound operators?
    By Nyda in forum C# Programming
    Replies: 2
    Last Post: 04-28-2004, 05:42 AM
  5. Operators
    By George in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 07:35 PM