Conversion Constructor help

This is a discussion on Conversion Constructor help within the C++ Programming forums, part of the General Programming Boards category; Hello, I am writing a class for a mixed number, and I have all of the operator overloads working and ...

Conversion Constructor help

Hello, I am writing a class for a mixed number, and I have all of the operator overloads working and such when it comes to other mixed number objects. But My conversion constructor for if just an int is entered is not working. If someone could take a quick peak and see if anything jumps out, it would be much appreciated.

Declaration:

Code:

Mixed(int w = 0);

Definition:

Code:

Mixed::Mixed(int w){
whole = w;
numerator = 0;
denominator = 1;
}

These are the operations I am trying to perform and getting a type conversion error:

I'd post all of your code, for now we can probably only guess various problems with your implementation (i.e., did you properly overload the "<<" operator of your class). Its also a good idea to post the exact error message (not the "type" of error message).

Hello, I am writing a class for a mixed number, and I have all of the operator overloads working and such when it comes to other mixed number objects. But My conversion constructor for if just an int is entered is not working. If someone could take a quick peak and see if anything jumps out, it would be much appreciated.

Declaration:

Code:

Mixed(int w = 0);

Definition:

Code:

Mixed::Mixed(int w){
whole = w;
numerator = 0;
denominator = 1;
}

These are the operations I am trying to perform and getting a type conversion error:

For those operations to invoke your constructor that takes an int, you'd have to have written operator overloads of +, -, *, and /. Perferably the two-parameter friend version so that both sides are implicitly convertible. I would also bracket the calculations so that the operator precedence is more explicit.
You should also be using a "constructor initialisation list".