jamoma / JamomaCore

Jamoma Frameworks for Audio and Control Structure
Other
36 stars 14 forks source link

Why does TTValue constructor feel that TTInt32 is ambiguous? #191

Closed nwolek closed 9 years ago

nwolek commented 10 years ago

The compiler is fine with the following:

int myInt = 42;
TTValue myValue(myInt);

But it complains that the following is "ambiguous":

TTInt32 myTTInt = 42;
TTValue myAmbiguousValue(myTTInt);

Particularly weird is that the follow 2 seem legal:

TTUInt32 myUnsignedInt = 42;
TTValue myValue2(myUnsignedInt);
TTFloat32 myFloat = 42.78738;
TTValue myValue3(myFloat);

This issue has tripped me up several times. The complaint from the compiler always points to the following line of code instead of the point in the code where it is called, which makes it very hard to debug: https://github.com/jamoma/JamomaCore/blob/master/Foundation/library/includes/TTValue.h#L46

tap commented 10 years ago

This issue is a trip-up. To make it worse some compilers treat it differently than others. The compiler knows that a an int and TTInt32 are the same thing, so why not use that instead saying it can't figure out the difference between them?

Having been plagued by this for years, a very simple solution just occurred to me. Please make sure no C++ purist police are around. Maybe TTInt32 should not be a typedef but instead should be a #define.

best, | : ||

On Wed, Dec 11, 2013 at 7:26 AM, nwolek notifications@github.com wrote:

The compiler is fine with the following:

int myInt = 42; TTValue myValue(myInt);

But it complains that the following is "ambiguous":

TTInt32 myTTInt = 42; TTValue myAmbiguousValue(myTTInt);

Particularly weird is that the follow 2 seem legal:

TTUInt32 myUnsignedInt = 42; TTValue myValue2(myUnsignedInt); TTFloat32 myFloat = 42.78738; TTValue myValue3(myFloat);

This issue has tripped me up several times. The complaint from the compiler always points to the following line of code instead of the point in the code where it is called, which makes it very hard to debug:

https://github.com/jamoma/JamomaCore/blob/master/Foundation/library/includes/TTValue.h#L46

— Reply to this email directly or view it on GitHubhttps://github.com/jamoma/JamomaCore/issues/191 .

nwolek commented 10 years ago

I am most certainly not a member of the "C++ purist police". I am for whatever makes this time sink go away. :)

lossius commented 10 years ago

Oblique strategy of the day….

On 11 Dec 2013, at 15:07, Timothy Place notifications@github.com wrote:

Please make sure no C++ purist police are around.

tap commented 10 years ago

The TTValue unit test caught a bug caused by a typo I made :-) So good to catch that right away in Xcode!

Nilson commented 10 years ago

thumbs up for unit tests!