Clang (C++) 在专用化中找不到名称
clang (c++) can't find name within specialization
以下代码与gcc(g )一起编译,但对clang(c )抱怨。
我期望该行n1::generic(*it);
寻找my_traits<bool>
(或my_traits<const bool>
)专业化,但是,它似乎正在从同一专业中寻找vector
(const?)中的名称specific
。
另外,这是特定于布尔的。其他类型等类型的工作正常。(我尝试添加my_traits<vector<bool> >
(以及const bool)专业化,但没有帮助)。
#include <vector>
namespace n1 {
template <class T> struct my_traits { };
template <> struct my_traits<bool> {
static void specific(bool b) { }
};
template <> struct my_traits<int> {
static void specific(int b) { }
};
template <typename T> void generic(const T& t)
{
my_traits<T>::specific(t);
}
template <typename T> struct my_traits<std::vector<T> > {
static void specific(const std::vector<T>& b)
{
if (! b.empty()) {
for (typename std::vector<T>::const_iterator it = b.begin();
it != b.end(); ++it) {
n1::generic(*it);
}
}
}
};
}
namespace n2 {
struct ArrayOfBoolean {
std::vector<bool> values;
};
struct ArrayOfInt {
std::vector<int> values;
};
}
namespace n1 {
template<> struct my_traits<n2::ArrayOfBoolean> {
static void specific(const n2::ArrayOfBoolean& v) {
n1::generic(v.values);
}
};
template<> struct my_traits<n2::ArrayOfInt> {
static void specific(const n2::ArrayOfInt& v) {
n1::generic(v.values);
}
};
}
c++ codec.cc -o codec
In file included from codec.cc:1:./codec.h:17:23: error: no member named 'specific' in 'n1::my_traits<std::__1::__bit_const_reference<std::__1::vector<bool,std::__1::allocator<bool> > > >'
my_traits<T>::specific(t);
~~~~~~~~~~~~~~^
./codec.h:26:25: note: in instantiation of function template specialization 'n1::generic<std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > > >' requested here
n1::generic(*it);
^
./codec.h:17:23: note: in instantiation of member function 'n1::my_traits<std::__1::vector<bool, std::__1::allocator<bool> > >::specific' requested here
my_traits<T>::specific(t);
^
./codec.h:47:17: note: in instantiation of function template specialization 'n1::generic<std::__1::vector<bool, std::__1::allocator<bool> > >' requested here
n1::generic(v.values);
^
1 error generated.
奇数看起来, vector<bool>
不能容纳任何bool
s。只有您无法真正参考的位。
所以在n1::generic(*it);
中没有const bool&
,只有__bit_const_reference
代理类。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 找不到QtResource文件中的文件
- VC++本机单元测试,找不到调试符号
- RegGetValue在当前用户下找不到名称
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- c++找不到具有相同哈希的无序集合元素
- 找不到以下加速库:boost_fiber
- 找不到 FLTK(缺少:FLTK_INCLUDE_DIR)
- 设置 Visual Studio for MPI: 找不到标识符错误
- "assimp/config.h"找不到,但它在文件夹中
- 链接器找不到在虚拟类 c++ 中访问的静态字段的符号
- C++系统找不到指定的文件错误
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 找不到用于专用化的定义的"内联"模板方法
- Clang (C++) 在专用化中找不到名称
- 带有可变模板的C++异步找不到正确的函数模板专用化