Strange C++ compiling error

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?
 
Ö

Öö Tiib

I encounter a "no matching function for call" error. My code is like this:

Seems mostly valid code.
B::init()
{
A::func(b_1, b_2, b_3); //LINE2
}

Here must be 'void B::init()'.

Either you did not post actual code or you are using some strange
C++ compiler (or both of course). Can you copy paste actual code
what you tried and tell what compiler it is?
 
M

Marcel Müller

On 09.12.13 00.23, Jun W wrote:

Either a compiler bug or it is not your code.
B::init()
{
A::func(b_1, b_2, b_3); //LINE2
}

At least this does not compile. The return type void is missing.

However, with this fix it compiles fine, even with very old compilers
like IBM VisualAge C++.


Marcel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top