c++ - 使用 C++ 模板参数作为另一个模板的参数?

标签 c++ templates syntax-error

<分区>

我正在尝试编译以下代码:

template <typename K, typename V>
static void addMapping(const K& id, const V& index, std::map<K, V>& mapset) 
{
    std::pair< std::map<K, V>::iterator, bool > ret;
    // ...
}

但我收到以下错误消息:

error: type/value mismatch at argument 1 in template parameter list for ‘template<class _T1, class _T2> struct std::pair’
     std::pair< std::map<K, V>::iterator, bool > ret;

我记得当你想使用一个模板参数作为另一个模板的参数时,你需要写一些特别的东西,但我不记得那是什么......

最佳答案

改变这一行:

std::pair< std::map<K, V>::iterator, bool > ret;

进入:

std::pair< typename std::map<K, V>::iterator, bool > ret;

作为std::map<K, V>::iterator取决于您需要告诉编译器它是一种类型的模板参数。

关于c++ - 使用 C++ 模板参数作为另一个模板的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22355398/

相关文章:

c++ - C++11 是否允许 vector<const T>?

c++ - 在 Visual C++ 控制台应用程序中显示图像?

c++ - 从第一类型的第二个非类型参数推导第一类型

c++ - 编译错误 : expected ‘)’ before ‘&’ token

c++ - Gtkmm TreeView : Accessing dynamically added columns

c++ - 在这种情况下,为什么 STL priority_queue 并不比 multiset 快多少?

使用模板与内联的 C++ 元编程

c++ - 如何从头文件中拆分模板构造函数?

compiler-errors - 如何从 Ocaml 编译器中获取更多信息

ruby - 更改此Ruby类的名称会导致错误