Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange C++ compiling error

31 views
Skip to first unread message

Jun W

unread,
Dec 8, 2013, 6:23:40 PM12/8/13
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?

Öö Tiib

unread,
Dec 8, 2013, 6:39:59 PM12/8/13
to
On Monday, 9 December 2013 01:23:40 UTC+2, Jun W wrote:
> 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?

Marcel Müller

unread,
Dec 8, 2013, 7:04:05 PM12/8/13
to
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
0 new messages