Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return the wrong type in C++

Tags:

c++

I have a class Color that contains three float components (r, g, b).

I have to program the following function :

Color getColor(unsigned char values[], int i)

Normally I should program it like this :

Color getColor(unsigned char values[], int i){
     return Color((float) values[i]/255.0, (float) values[i+1]/255.0, (float) values[i+2]/255.0);
}

But by error I did

return values[i];

When I compiled I didn't get any compilation error and I haven't get run time error either.

Why this is possible?

like image 763
Hunsu Avatar asked Nov 18 '14 11:11

Hunsu


1 Answers

This could be a result of non-explicit constructor of Color class accepting unsigned char as its argument.

That means you have constructor in Color class with single argument OR multiple arguments rest being default parameters.

like image 162
ravi Avatar answered Sep 20 '22 07:09

ravi