Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++ Instantiate template template class

I am trying to implement my own container (in my demonstration called Manager), which stores another templated container (e.g Node<T>).
Therefore I am trying to instantiate an object like Mgr<Node<T>>.
After reading through all of the template template-articles on here, I came to the following demonstration code.

#include <iostream>

template<typename T>
struct Node {
    T data;
    int id;
};

template<template<typename> class Container, typename T>
struct Mgr {
    Container<T> nodes;
    int id;
    void print()
    {
        std::cout << this->id;
    }
};

int main() {
    Mgr<Node<char>, char> mgr;
    mgr.print();
    return 0;
}

Compiling this still gives me the error message: type/value mismatch at argument 1 in template parameter list for 'template<template<class> class Container, class T> struct Mgr...Expected a class template, got Node<char>
Is my function definition wrong, or do my instantiation parameters incorrect?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

template<typename> class Container expect that you pass a template as Container, Node<char> is not a template, it’s a concrete type.

You want
Mgr<Node, char> mgr;

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading