Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What arguments must I pass to a function to perform an implicit construction of an object?

Tags:

c++

My apologies if this is a dupe. I found a number of posts re. preventing implicit conversions, but nothing re. encouraging implicit constructions.

If I have:

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

and the free function:

Rect Scale( const Rect & );

why would

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

not do an implicit construction of a const Rect& and instead generate this compiler error

'Scale' : function does not take 4 arguments
like image 378
BeeBand Avatar asked Nov 05 '10 11:11

BeeBand


1 Answers

Because the language does not support this feature. You have to write

Rect s = Scale(Rect(137.0f, 68.0f, 235.0f, 156.0f));
like image 82
SebastianK Avatar answered Oct 05 '22 02:10

SebastianK