Jun W
unread,Dec 8, 2013, 6:23:40 PM12/8/13You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
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?