J
Jun W
I encounter a "no matching function for call" error. My code is like this:
f1.h
class A
{
public:
A(){}
static void func(unsigned int a1, int a2, unsigned int & a3);
};
f1.cpp
#include "f1.h"
void A::func(unsigned int a1, int a2, unsigned int & a3)
{
//body of the function.
}
f2.h
class B
{
public:
B();
void init();
private:
unsigned int b_1;
int b_2;
unsigned int b_3;
};
f2.cpp
#include "f1.h"
#include "f2.h"
B::B()
{
A::func(b_1, b_2, b_3); //LINE1
}
B::init()
{
A::func(b_1, b_2, b_3); //LINE2
}
When compile the code, the error at both LINE1 and LINE2 are:
f2.cpp:error: no matching function for call to ‘A::func(unsigned int&, int&, unsigned int&)’ f1.h: note: candidates are: static void A::func(unsigned int a1, int a2, unsigned int & a3)
If I change the signature of A::func() in f1.h and f1.cpp to:
void func(unsigned int& a1, int& a2, unsigned int & a3)
The error is still:
f2.cpp:error: no matching function for call to ‘A::func(unsigned int&, int&, unsigned int&)’ f1.h: note: candidates are: static void A::func(unsigned int& a1, int& a2, unsigned int & a3)
How can the compiler decide that LINE1 and LINE2 need "pass by reference" for the three arguments?
f1.h
class A
{
public:
A(){}
static void func(unsigned int a1, int a2, unsigned int & a3);
};
f1.cpp
#include "f1.h"
void A::func(unsigned int a1, int a2, unsigned int & a3)
{
//body of the function.
}
f2.h
class B
{
public:
B();
void init();
private:
unsigned int b_1;
int b_2;
unsigned int b_3;
};
f2.cpp
#include "f1.h"
#include "f2.h"
B::B()
{
A::func(b_1, b_2, b_3); //LINE1
}
B::init()
{
A::func(b_1, b_2, b_3); //LINE2
}
When compile the code, the error at both LINE1 and LINE2 are:
f2.cpp:error: no matching function for call to ‘A::func(unsigned int&, int&, unsigned int&)’ f1.h: note: candidates are: static void A::func(unsigned int a1, int a2, unsigned int & a3)
If I change the signature of A::func() in f1.h and f1.cpp to:
void func(unsigned int& a1, int& a2, unsigned int & a3)
The error is still:
f2.cpp:error: no matching function for call to ‘A::func(unsigned int&, int&, unsigned int&)’ f1.h: note: candidates are: static void A::func(unsigned int& a1, int& a2, unsigned int & a3)
How can the compiler decide that LINE1 and LINE2 need "pass by reference" for the three arguments?