gpt4 book ai didi

c++ - g++ 4.7.2 用于类型别名的处理似乎被打破

转载 作者:太空狗 更新时间:2023-10-29 23:05:42 26 4
gpt4 key购买 nike

在下面的代码中,g++ 4.7.2 会被基于using 的类型别名混淆。

代码:

#include <map>

enum class Direction
{
UP=-1,
DOWN=1
};

template <Direction dir>
struct Comparator
{
bool operator()(int lhs, int rhs) const
{
return lhs<rhs; // Comparison should be based on dir
// but let's not even use dir for now
}
};

template <Direction dir>
using IntToIntMap=std::map<int, int, Comparator<dir>>;

template <Direction dir>
void TestFunc()
{
using TheMap=IntToIntMap<dir>; // TheMap should be a synonym for
// IntToIntMap<dir>

typename IntToIntMap<dir>::value_type value1; // This compiles
typename TheMap::value_type value2; // This does not (???)
}

int main()
{
TestFunc<Direction::UP>();
}

编译代码:

g++ -std=c++11 -Wall --pedantic -o test test.cpp

意外的编译时错误:

test.cpp: In instantiation of 'void TestFunc() [with Direction dir = 
(Direction)-1]
test.cpp:34:29: required from here
test.cpp:29:33: error: no type named 'value_type' in 'using TheMap =
IntToIntMap<dir>'

有问题的行有什么问题?代码是否违反了 C++11 标准,或者这是一个 g++ 4.7.2 错误? Live code in g++-4.7

最佳答案

关于c++ - g++ 4.7.2 用于类型别名的处理似乎被打破,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18213638/

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