no match for call to

Hi everyone,
I know this problem has been encountered thousands of times before, so I checked everywhere on the net but I still did not manage to solve this problem this time.
It is apparently due to a confusion with the initialization of the class and a function.
Here is the interesting part of the code:

A function in main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
Frac demanderfrac(Frac eg)
{
    int num;
    int denom;
    cout << "Enter number 1: ";
    cin >> num;
    cout << endl;
    cout << "Number 2 now: ";
    cin >> denom;
    cout << endl;
    return eg(num, denom); //Here is the error: no match for call to '(Frac) (int&, int&)'
}


and Frac.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef DEF_FRAC
#define DEF_FRAC

#include <iostream>

class Frac
{
    public:
    Frac(int numerateur = 0, int denominateur = 1);
    //Frac(int entier = 1);
    double getm_valeurexacte();
    void afficher(std::ostream &flux) const;

    Frac& operator+=(Frac const& autre);
    Frac& operator-=(Frac const& autre);
    Frac& operator*=(Frac const& autre);
    Frac& operator/=(Frac const& autre);

    private:
    int m_numerateur;
    int m_denominateur;
    double m_valeurExacte;
};

    Frac operator+(Frac const& a, Frac const& b);
    Frac operator-(Frac const& a, Frac const& b);
    Frac operator*(Frac const& a, Frac const& b);
    Frac operator/(Frac const& a, Frac const& b);

#endif 


And the last one Frac.cpp
1
2
3
4
5
6
7
8
#include "Frac.h"
#include <cstdlib>
using namespace std;

Frac::Frac(int numerateur, int denominateur) : m_numerateur(numerateur), m_denominateur(denominateur), m_valeurExacte(m_numerateur / m_denominateur)
{

}


I really need help on this one... tell me if you need more!
Thanks for every comment you leave ;)
If the demanderfrac function is supposed to do what I think it does, I would change it to either this:

1
2
3
4
5
6
7
8
9
10
11
12
Frac demanderfrac()
{
    int num;
    int denom;
    cout << "Enter number 1: ";
    cin >> num;
    cout << endl;
    cout << "Number 2 now: ";
    cin >> denom;
    cout << endl;
    return Frac(num, denom);
}

or this:

1
2
3
4
5
6
7
8
9
10
11
12
void demanderfrac(Frac &eg)
{
    int num;
    int denom;
    cout << "Enter number 1: ";
    cin >> num;
    cout << endl;
    cout << "Number 2 now: ";
    cin >> denom;
    cout << endl;
    eg = Frac(num, denom);
}
Your problem is contained in the following snippet:
1
2
3
4
Frac demanderfrac(Frac eg)
{
    return eg(num, denom); //Here is the error: no match for call to '(Frac) (int&, int&)'
}


First eg is a variable, an instance of your Frac class that you passed into this function as a parameter. If you want to return this variable then you would just use:
return eg;
You would then need to use a public function in your class to alter the private variables of your class.

If you want to return a different Frac then you could do something like:
return Frac(num, denom);
But then you wouldn't need to pass eg into this function.

Thank you so much fg109 I did like your first suggestion and it worked perfectly, the only thing is that I wouldn't be able to do it by myself, but I understood how it worked.
So the only thing I want to tell you all now is thank you ;)
Topic archived. No new replies allowed.