template class problem

This is a discussion on template class problem within the C++ Programming forums, part of the General Programming Boards category; Can somebody please tell me, whats wrong with this: Code: template <typename T> class base_record { public: typedef std::vector<T> list_type; ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    template class problem

    Can somebody please tell me, whats wrong with this:

    Code:
    template <typename T>
    class base_record {
    public:
    	typedef std::vector<T> list_type;
    
    	list_type const& records() const { return m_records; }
    
    private:
    	list_type m_records;
    	list_type::size_type m_position; //the problem is here
    };

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    You need to put the keyword typename in front of the declaration in red to indicate to the compiler that size_type is a type.

  3. #3
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Thanks Daved!

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You didn't say what error you're getting if any, but without trying to compile it, I'd say try this:
    Code:
    typename list_type::size_type m_position;

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Solution suggested and implemented and problem solved before you could add colour to your response.

    More information about typename: http://publib.boulder.ibm.com/infoce...d_typename.htm
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function template has already been defined
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 04-14-2009, 10:17 AM
  2. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Template problem
    By LilShieste in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2002, 12:17 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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