Starx wrote:

I am writing a fraction class and I was testing my addition operator to

find out how big the numerator and denominator can be before an

overflow occurs. I was doing it like this:

fraction frac1(10001, 10000); //Creates 10001/10000

cout << frac1 << " * 2 = " << frac1 + frac1 << endl;

I then proceeded to add zero's to the first line and kept executing the

program and looking for an obviously wrong result as an indication of

overflow. A curious thing happened. This test:

fraction frac1(1000000001, 1000000000);

cout << frac1 << " * 2 = " << frac1 + frac1 << endl;

compiles fine and outputs a correct result. This test:

fraction frac1(10000000001, 10000000000);

cout << frac1 << " * 2 = " << frac1 + frac1 << endl;

which has 1 extra 0 added to the both the numerator and denominator,

doesn't compile. It gives me error C2668: 'fraction::fraction' :

ambiguous call to overloaded function. Now my fraction constructors

can handle int and long int which can be either signed or unsigned and

the numerator doesn't have to be the same type as the denominator, you

can mix and match. I'm running VC++ 6.0 and normally when I just type

numbers into the source code (as I've done here) and those numbers have

no decimal, they are interpreted as type int. So when the numbers get

large enough are they interpreted as a different type?? If so how do I

find out what type that is?

If an integer literal starts with a 0 (eg, 0123, 0532, it is interpreted

as an octal number. If it starts with 0x (eg. 0xF3) is it interpreted

as hexidecimal. Beyond that, here is what the standard has to say about it.

2.13.1.2:

The type of an integer literal depends on its form, value, and suffix.

If it is decimal and has no suffix, it has the first of these types in

which its value can be represented: int, long int; if the value cannot

be represented as a long int, the behavior is undefined. If it is octal

or hexadecimal and has no suffix, it has the first of these types in

which its value can be represented: int, unsigned int, long int,

unsigned long int. If it is suffixed by u or U, its type is the first of

these types in which its value can be represented: unsigned int,

unsigned long int. If it is suffixed by l or L, its type is the first of

these types in which its value can be represented: long int, unsigned

long int. If it is suffixed by ul, lu, uL, Lu, Ul, lU, UL, or LU, its

type is unsigned long int.