tags:

views:

143

answers:

3

This is the situation:

int f(int a){
    ...
    g(a);
    ...
}

void g(int a){...}

The problem is that the compiler says that there is no matching function for call to g(int&). It wants me to pass the variable by reference and g() recieves parameters by value.

How can I solve this?

+11  A: 

Well, there's not much here, but the first thing is: make sure you have a declaration for g that's included before f is defined.

void g(int a);

Otherwise, when you get to f, function f has no idea what function g looks like, and you'll run into trouble. From what you've given so far, that's the best I can say.

Michael Kohne
yes, it is. If I declared g() as: g(int it would work, but that's not what I want to do.
Gerardo
@macaco: I think you need to post some more code then. What you have posted will not invoke any errors.
Lucas
+1 from the given code, that's the same I can guess too
Devil Jin
+1  A: 

Your function g() needs to be defined above f()

Ponting
You mean *declared*. The compiler looks for the existence of functions, and later links to the actual implementation (the *definition*).
Cecil Has a Name
yes that would also work, but if it is simple function better *define* it it above
Ponting
A: 

There are two things wrong:

1) g is not declared before it is used, so the compiler will compain about that. Assuming you fixed that issue, then the next issue is:

2) f is not returning an int.

Kyle Walsh