【问题标题】:Class template value without template arguments error [duplicate]没有模板参数的类模板值错误[重复]
【发布时间】:2021-02-07 07:38:23
【问题描述】:

我有一些代码:

template<typename Container = std::vector> // there is error
class SomeClass {
    struct SomeDataStructure {
        int a;
        float b;
    };

    Container<SomeDataStructure> container; // and there
};

我想在其他模板类的模板参数中传递模板类类型。
在这个例子中,我想将std::vector 传递给SomeClass 并定义私有结构SomeDataStructureContainer(std::vector)。
但我收到错误(MSVC 编译器)C2059C2238
我该如何解决?
提前致谢!

【问题讨论】:

  • 当遇到编译器错误时,请在问题中包含完整的错误消息。错误代码特定于编译器,而任何编译器的代码问题都相同。无论如何,您需要一个模板模板参数,如副本中所述

标签: c++ templates


【解决方案1】:

您需要模板模板参数:

template<template<class, class...> class Container = std::vector>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2019-09-06
    • 2018-12-03
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多