Firtly, I would like to mention that I have searched through similar fourm topics with questions similar to mine but I have still not found a solution.
My problem ios this, my program is not compiling and I'm getting this error message...
error: no matching function call to 'main_XavierLinn::fraction::fraction(int)'
I have two constructors one defualt to assign values to member variables if no arguments are passed and one to assign values if arguments are passed.
//CLIENT CODE....
#include <iostream>
#include "fraction.h"
#include <fstream>
using namespace std;
using namespace main_XavierLinn;
void BasicTest();
int main()
{
BasicTest();
}
void BasicTest()
{
cout << "\n----- Testing basic fraction creation & printing\n";
cout << "(fractions should be in reduced form, and as mixed numbers.)\n";
for (int i = 0; i < 7; i++){
cout << "fraction [" << i <<"] = " << fr[i].numerator << endl;
}
}
// FILE: fraction.h
// CLASS PROVIDED: fraction (part of the namespace main_XavierLinn
//
// CONSTRUCTOR for fraction class:
// fraction(int initial_numerator = 0, initial_denominator = 1)
// Postcondition: The fraction has been intialized to zero
The problem is that the main file sees only the definition of class fraction where the constructor with two parameters has no default arguments. So the compiler reports the error because it did not find matching constructor. You should declare the second constructor with two parameters as having a default argument for the second parameter and function specifier explicit. For example
class fraction
{
public:
// DEFAULT CONSTRUCTOR
fraction();
// CONSTRUCTOR explicit fraction(int initial_numerator, int initial_denominator = 0 );
int numerator; // numerator of fraction
int denominator; // denominator of fraction
};