C4305 truncation from 'const unsigned int' to 'bool'

firescript 2021-03-24 09:09:05
下面的typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);这句报错:

error C4305: 'specialization' : truncation from 'const unsigned int' to 'bool'

请问,怎么修改 ?

template<typename Derived>
template<typename OtherDerived>
inline typename MatrixBase<Derived>::PlainObject
MatrixBase<Derived>::cross3(const MatrixBase<OtherDerived>& other) const
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4)
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4)

typedef typename internal::nested<Derived,2>::type DerivedNested;
typedef typename internal::nested<OtherDerived,2>::type OtherDerivedNested;
const DerivedNested lhs(derived());
const OtherDerivedNested rhs(other.derived());

return internal::cross3_impl<Architecture::Target,
typename internal::remove_all<DerivedNested>::type,
typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
}



namespace internal {

template< int Arch,typename VectorLhs,typename VectorRhs,
typename Scalar = typename VectorLhs::Scalar,
bool Vectorizable = (VectorLhs::Flags&VectorRhs::Flags)&PacketAccessBit>
struct cross3_impl {
inline static typename internal::plain_matrix_type<VectorLhs>::type
run(const VectorLhs& lhs, const VectorRhs& rhs)
{
return typename internal::plain_matrix_type<VectorLhs>::type(
internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
0
);
}
};
...全文
359 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2021-03-24
  • 打赏
  • 举报
回复
error C4305: 'specialization' : truncation from 'const unsigned int' to 'bool'
这个错误提示是把const unsigned int类型转成了bool类型,这样数据被截断了。truncation就截断了嘛
比如把100赋值给bool,bool就是0或1.
firescript 2021-03-24
  • 打赏
  • 举报
回复
引用 3 楼 自信男孩 的回复:
[quote=引用 2 楼 firescript 的回复:][quote=引用 1 楼 自信男孩 的回复:]error C4305: 'specialization' : truncation from 'const unsigned int' to 'bool'
这个错误提示是把const unsigned int类型转成了bool类型,这样数据被截断了。truncation就截断了嘛
比如把100赋值给bool,bool就是0或1.



如果让int就是转化为bool,不提示错误 如何 cast ?[/quote]

需要看一下bool的后台定义了。首先unsigned int 与int本身标识的范围不一样,unsigned int表示正整数比int多,也是有截断的[/quote]



已解决,多谢!


自信男孩 2021-03-24
  • 打赏
  • 举报
回复
引用 2 楼 firescript 的回复:
[quote=引用 1 楼 自信男孩 的回复:]error C4305: 'specialization' : truncation from 'const unsigned int' to 'bool'
这个错误提示是把const unsigned int类型转成了bool类型,这样数据被截断了。truncation就截断了嘛
比如把100赋值给bool,bool就是0或1.



如果让int就是转化为bool,不提示错误 如何 cast ?[/quote]

需要看一下bool的后台定义了。首先unsigned int 与int本身标识的范围不一样,unsigned int表示正整数比int多,也是有截断的
firescript 2021-03-24
  • 打赏
  • 举报
回复
引用 1 楼 自信男孩 的回复:
error C4305: 'specialization' : truncation from 'const unsigned int' to 'bool'
这个错误提示是把const unsigned int类型转成了bool类型,这样数据被截断了。truncation就截断了嘛
比如把100赋值给bool,bool就是0或1.



如果让int就是转化为bool,不提示错误 如何 cast ?

65,197

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧