i created a fraction class and now im trying to create an overload operator for the power function to take a fraction to the "n" power, but Im getting an identifier undefined error for *tmp. Any help on this problem would be greatly appreciated. I have posted the overload code from the h file and the code from the exp function from the cpp file.
if (sign > 0)
Fraction *tmp = new Fraction(numer, denon); // declare tmp
// tmp is out of scope (one line scope )
else //if (*num != 0).... else ......
Fraction *tmp = new Fraction(denon, numer); // same here as above
return *tmp; //undefined
to be more clear..
I will also give this example
1 2 3 4 5 6 7 8 9
if (something)
int x = 6 ;
elseint x = 17 ;
// x is out of scope
cout << x ; //undefined
The right way to do this
1 2 3 4 5 6 7 8
int x ;
if (something)
x = 6;
else
x = 17 ;
cout << x ; //Ok
Also you have caused memory leak when the pointer (tmp)
out of scope and not freed .. so be careful