Thread: Another template question...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by Elysia View Post
    Just two notes:
    • It's possible to write typename instead of class. The class keyword is actually an old keyword maintained for backwards compatibility.
    • Be careful with T1<T2<T3>>. This is not valid C++03 (two > in template declarations must not exist in C++03; separate them with spaces), but it is valid C++0x.
    First point is noted. Will use typename from now.

    I'm not sure how you mean with the 2nd point. How should the template declaration have been written for C++03?

    Thanks again.

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by darren78 View Post
    I'm not sure how you mean with the 2nd point. How should the template declaration have been written for C++03?
    I forgot about this since my compiler has extensions allowing it. The problem is a potential parse error caused by '>>'.
    Code:
    vector<pairs<string, int>> pair;
    C++03 will interpret >> as operator>>, not as the closing brackets of a template. To fix it, you have to include spaces.
    Code:
    vector<pairs<string, int> > pair;
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template already instantiated
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2010, 12:42 PM
  2. Assignment issues
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2010, 12:55 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Quick question about class template
    By merixa in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2005, 11:43 PM
  5. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM