c++ - 我必须将哪些参数传递给函数才能执行对象的隐式构造?

标签 c++

如果这是一个骗局,我深表歉意。我发现了很多帖子。防止隐式转换,但没有任何意义。鼓励隐式构造。

如果我有:

class Rect
{
public:
    Rect( float x1, float y1, float x2, float y2){};
};

和免费功能:

Rect Scale( const Rect & );

为什么会

Rect s = Scale( 137.0f, 68.0f, 235.0f, 156.0f );

不进行 const Rect& 的隐式构造,而是生成此编译器错误

'Scale' : function does not take 4 arguments

最佳答案

因为语言不支持这个特性。你必须写

Rect s = Scale(Rect(137.0f, 68.0f, 235.0f, 156.0f));

关于c++ - 我必须将哪些参数传递给函数才能执行对象的隐式构造?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4105539/

相关文章:

c++ - 无法将类型转换为类型* - C++ 编译错误

C++ 迭代器 : no appropriate default constructor available

c++ - std::vector<char> 到 std::vector<T> 转换 c++

c++ - 如何打印包含集合的 map 内容?

c++ - OpenMP 仅使用一个线程

c++ - 在 C++ 中使用 'static_cast' 向下转换

c++ - 如何声明相互引用的类?

c++ - 是否有使用unicode字符串文件路径进行fopen的标准方法?

c++ - 错误: invalid types 'int[int]' for array subscript

constexpr 函数中存在 C++ Wconversion 警告,但模板中没有