gpt4 book ai didi

C++ 类型别名错误 : expected unqualified-id before 'using'

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:14 25 4
gpt4 key购买 nike

有很多资源解释了如何进行类型别名,但显然我遗漏了一些东西。我正在尝试创建 map 别名。调试时,我希望我的 Map_t 成为标准库 map,因为它更容易查看它包含的内容,而在不调试时,我希望它成为 btree: :btree_map 因为它使用的内存更少。

为此,我尝试了以下方法:

#if DEBUG
#include <map>
template<typename U, typename V>
using Map_t = map<typename U, typename V>; // <--- Error on this line
#else
#include "btree_map.h"
template<typename U, typename V>
using Map_t = btree::btree_map<typename U,typename V>; // <--- Error on this line
#endif

编译时出现错误 error: expected unqualified-id before 'using'。我已经尝试了上述的几种变体但没有成功。预先感谢您的意见。

更新:我觉得包括 btree 部分可能会让这有点困惑。所以让我扩展一下。如果我将我的类型声明为 say either

btree::btree_map<int, int> mymap;

map<int, int> mymap;

一切顺利。但只是想介绍一下

template<typename U, typename V>
using Map_t = map<U, V>;

Map_t<int, int> mymap;

导致错误。

最佳答案

你的语法有点错误。你需要

template<typename U, typename V>
using Map_t = map<U, V>;

至于btree段,要看btree的细节。如果它是一个带有名为btree_map的类模板的命名空间,那么你需要

template<typename U, typename V>
using Map_t = btree::btree_map<U, V>;

如果它是一个带有内部类型的类模板,那么你可能需要类似的东西

template<typename U, typename V>
using Map_t = typename btree<U,V>::btree_map;

关于C++ 类型别名错误 : expected unqualified-id before 'using' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24680660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com