【问题标题】:Why is no return type specified in this function clearly returns? [duplicate]为什么这个函数中没有指定返回类型明确返回? [复制]
【发布时间】:2012-12-04 09:26:30
【问题描述】:

可能重复:
Operator overloading

我在一段示例代码中看到了这一点:

operator Vector2<float>() const    {       
  return Vector2<float>(x, y);    }

我对此的 2 个问题:

1) 函数明明返回,却没有指定返回类型?

2) 不清楚这里究竟是什么重载,哪个运算符。

【问题讨论】:

  • 见末尾this answer
  • Vector2&lt;float&gt; operator Vector2&lt;float&gt;() const 有点多余,不是吗? :)

标签: c++


【解决方案1】:

是一个转换运算符,返回类型是Vector2&lt;float&gt;

【讨论】:

    猜你喜欢
    • 2017-06-20
    • 2015-09-28
    • 2013-03-25
    • 2013-05-09
    • 1970-01-01
    • 2018-12-08
    • 2011-05-07
    • 2021-10-31
    • 1970-01-01
    相关资源
    最近更新 更多