我在Mac OS X上使用clang(CXX ='clang ++ -std = c ++ 11 -stdlib = libc ++'),增强1.53.0.
我想在unordered_map中使用uuid作为键,但是会出现以下错误:
/usr/bin/../lib/c++/v1/type_traits:748:38: error: implicit instantiation of undefined template
'std::__1::hash<boost::uuids::uuid>'
: public integral_constant<bool, __is_empty(_Tp)> {};
^
/usr/bin/../lib/c++/v1/unordered_map:327:54: note: in instantiation of template class
'std::__1::is_empty<std::__1::hash<boost::uuids::uuid> >' requested here
template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value
Run Code Online (Sandbox Code Playgroud)
...
/usr/bin/../lib/c++/v1/unordered_map:327:71: error: no member named 'value' in
'std::__1::is_empty<std::__1::hash<boost::uuids::uuid> >'
template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value
~~~~~~~~~~~~~~~~~^
Run Code Online (Sandbox Code Playgroud)
...
它是什么 - Boost中的一个错误,它使它与我的C++ lib不兼容?或者我做错了什么?任何解决方法?
有这样的代码:
#include <iostream>
class A{
int a;
int fun(){}
};
class B{
int a;
virtual int fun(){}
};
int main()
{
std::cout << sizeof(A) << " " << sizeof(B) << std::endl;
std::cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
4 8
Run Code Online (Sandbox Code Playgroud)
为什么B类比A类大4个字节?
我有这个代码,其中我试图从传递的参数中获取最大数字.由于某种原因,它不起作用,我不确定为什么.当我输入2个数字时代码有效,但当传递3个或更多时,我得到这些错误:
prog.cpp:在函数'int main()'中:
prog.cpp:31:29:错误:没有匹配函数来调用'max(int,int,int)'
prog.cpp:31:29:注意:候选是:
prog.cpp:24:30:注意:模板constexpr decltype(handle :: helper :: max(max :: args ...))max(Args ...)
prog.cpp:24:30:注意:模板参数推导/替换失败:
prog.cpp:替换'template constexpr decltype(handle :: helper :: max(args ...))max(Args ...)[with Args = {int,int,int }]':
prog.cpp:31:29:从这里需要
prog.cpp:24:30:错误:没有匹配函数来调用'handle :: helper :: max(int&,int&,int&)'
prog.cpp :24:30:注意:候选人是:prog.cpp:11:18:注意:静态T句柄:: helper :: max(T,T)[T = int; Args = {int,int}]
prog.cpp:11:18:注意:候选人需要2个参数,3个提供
prog.cpp:16:18:注意:static T handle :: helper :: max(T,T,Args ...)[与T = int; Args = {int,int}]
prog.cpp:16:18:注意:候选人需要4个参数,3个提供
这是程序:
#include <iostream>
namespace handle
{
template <typename... Args>
struct helper {};
template <typename T, typename... Args>
struct helper<T, Args...> …
Run Code Online (Sandbox Code Playgroud)