Thread: template C++

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    template C++

    I was reading about "template template parameters" and when i try this code out it results in compiler error, can anyone help me out ?
    Code:
    #include <cstdio>
    #include <list>
    #include <vector>
    #include <string>
    using namespace std;
    
    template<template<typename T> class containerType>
    class Container
    {
        containerType < int > intC;
    };
    
    int main()
    {
        Container<vector>vC;
        return 0;
    }
    Compile Error:
    Code:
    templates.cpp: In function ‘int main()’:
    templates.cpp:15: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<class T> class containerType> class Container’
    templates.cpp:15: error:   expected a template of type ‘template<class T> class containerType’, got ‘template<class _Tp, class _Alloc> class std::vector’
    templates.cpp:15: error: invalid type in declaration before ‘;’ token

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    Re

    Adding an allocator parameter removes the error

    Code:
    containerType < int,allocator<int> > intC;
    But is there anyway to avoid or make it default or something ?

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It seems sort of simpler to use a normal template and instantiate a Container<vector<int> >?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Dec 2010
    Location
    China
    Posts
    7
    Code:
    template<typename Type>
    class Container
    {
    public:
    	Container();
    };
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
    	Container<vector <int> > vC;
    	return 0;
    }
    we can see the <vector <int> > as a whole type.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment issues
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2010, 12:55 PM
  2. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 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