Thread: class template arg is a class template arg is a...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    class template arg is a class template arg is a...

    I'm writing a generic Vector class (vector as in linear algebra not STL std::vector). I want to use STL std::vector as the internal container.

    Code:
    #include <vector>
    
    template < class T > // specifies what types the std::vector will store
    class MyClass
    {
        public:
            MyClass(std::vector<T>::iterator begin, std::vector<T>::iterator end)
            {
                // blah
            }
            //...
        private:
            std::vector<T> m_data;
    };
    With g++ 4.1.2 I get the following compiler errors:

    Code:
    vec.h: error: expected `)' before ‘begin’
    I've tried using typedefs like:

    Code:
    typedef std::vector<T> Container;
    typedef Container::iterator Iterator;  // or typedef std::vector<T>::iterator Iterator;
    with no luck (nor did I expect it.)

    Any help please?
    Thank you

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You need this:

    >> MyClass(typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end)

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linker error
    By tasha302 in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2006, 12:00 AM
  2. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  3. Instantiating a template class
    By NullS in forum C++ Programming
    Replies: 11
    Last Post: 02-23-2005, 10:04 AM
  4. Function template in Class template?
    By Aidman in forum C++ Programming
    Replies: 3
    Last Post: 10-28-2003, 09:50 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM