加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 混淆(* this)指针的强制转换

发布时间:2020-12-16 09:43:14 所属栏目:百科 来源:网络整理
导读:这是Transform类中ROS( link)中的Transform.h代码. /**@brief Return the transform of the vector */TFSIMD_FORCE_INLINE Vector3 operator*(const Vector3 x) const{ return (*this)(x);} 有人可以解释这段代码在做什么吗?这就是我的想法(对于上下文,我有
这是Transform类中ROS( link)中的Transform.h代码.

/**@brief Return the transform of the vector */
TFSIMD_FORCE_INLINE Vector3 operator*(const Vector3& x) const
{
    return (*this)(x);
}

有人可以解释这段代码在做什么吗?这就是我的想法(对于上下文,我有几年的C程序员经验,第一次用C开发.)

调用以下函数时调用该函数

object_of_type_Transform * object_of_type_Vector3

然后它将Vector3对象转换为Transform对象并返回结果(我很不清楚这是如何可能的,因为这两种类型似乎不兼容).

但返回的结果是Vector3 ……这就是我的心智模型崩溃的地方.

另外,该函数应该是基于Transform类转换Vector3点…所以我的理解肯定是有缺陷的.

我很感激任何见解.

谢谢

编辑

谢谢回复!上面的功能是:

/**@brief Return the transform of the vector */
TFSIMD_FORCE_INLINE Vector3 operator()(const Vector3& x) const
{
    return Vector3(m_basis[0].dot(x) + m_origin.x(),m_basis[1].dot(x) + m_origin.y(),m_basis[2].dot(x) + m_origin.z());
}

/**@brief Return the transform of the vector */
TFSIMD_FORCE_INLINE Vector3 operator*(const Vector3& x) const
{
    return (*this)(x);
}

我明白了,现在,我们还在继续.再次感谢.

解决方法

It then casts the Vector3 object into a Transform object and returns that as a result

不,没有演员阵容;这个:

return (*this)(x);

相当于:

return this->operator()(x);

在这两种情况下,代码都在调用Transform :: operator()并将x传递给它.第一个代码中的括号是必要的,因为()绑定比*强,所以没有围绕*的括号,这个代码将等同于return *(this(x)); – 编译错误.

顺便说一句,这是非常惯用的C代码,但我可以看到语法如何让C程序员感到困惑(毕竟,你不能重载运算符,更不用说运算符()).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读