lundi 11 octobre 2021

Template Template C++ code does not work when called from within a template function [duplicate]

So I have just recently started my journey down using templates in c++, and one of the interesting things I found were template templates. but I noticed when I tried to use them that they only work if the location where they are used has a fully defined type (or something...). For instance see below:

template<typename T>
class vectorWrap
{
    public:
    template<template <typename> class container>
    container<T>* test(){
        return new container<T>();
    }
};

template <typename T>
void fnTest()
{
    vectorWrap<T> wrap;
    auto ret =wrap.test<std::vector>();//if this line is commented out it compiles
}

int main(int argc, char const *argv[])
{
    vectorWrap<int> wrap;
    auto ret =wrap.test<std::vector>();

    fnTest<T>();
    return 0;
}

Of course, I am not really sure if template templates are the right choice for my problem (probably not), but I would regardless like to know what is going on with this, because it seems unintuitive...

If it is compiler specific I am using GCC 7.5, I have not tested other compilers.

Aucun commentaire:

Enregistrer un commentaire