Templates....

This is a discussion on Templates.... within the C++ Programming forums, part of the General Programming Boards category; My struggle against templates continues. Say I have this code AutoPtr< int > scores( new int[ 10 ] ); Then ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Templates....

    My struggle against templates continues. Say I have this code
    AutoPtr< int > scores( new int[ 10 ] );

    Then I have the following loop.

    for ( int i = 0; i < NUM_SCORES; i++ )
    {
    cout << scores[ i ] = i * 2;
    }

    Do I need to overload the = operator as well as the << and the [] operators?? How would the << operator look? I already have done the [] operator overload. Thanks

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    [] aren't operators are they?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Yep, they are operators, the only operators that cannot be overloaded are as follows:

    . (Direct Member select)
    ? : (conditional expression)
    :: (scope resolution)
    .* (Direct Member selection
    sizeof (size of object or type)

    I'm pretty sure that's right. Can anyone else confirm?

  4. #4
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    I also doubt you could overload -> but what you said makes sense although I am not very far into operator overloading and such.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by tim545666
    I also doubt you could overload -> but what you said makes sense although I am not very far into operator overloading and such.
    -> Can only be overloaded as a member function.

  6. #6
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    Can you overload & too?

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by tim545666
    Can you overload & too?
    Yep, no problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 12:49 AM
  2. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-17-2005, 11:22 PM
  3. templates and inheritance problem
    By kuhnmi in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 02:46 AM
  4. When and when not to use templates
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 07-20-2003, 09:36 AM

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