-2

i'm not a c++ guru at all, and i've tried to replicate this error in variuos little trials. the fact is that when i do a little program with 2 o 3 classes with what i wanto to do, there is no error. but in the main applicaiton i'm tring to write the error persist even if i've tried a lot of (even nonsense) solutions.

the problem is that i have a main class that instantiate some resources (as pointers) and a strategy pattern that istantiate different concrete behaviours that take in constructors thoose resources.

in main app, init():

device = new Kinect();
controls = new Gui();

UserPositionBehaviour = new UserPositionBehaviour(device, controls);

and, behaviour constructor:

UserPositionBehaviour(Kinect * device, Gui * controls);

this is the error:

src/App.cpp:30: error: no matching function for call to ‘UserPositionBehaviour::UserPositionBehaviour(Kinect*&, ofTrueTypeFont*&, ofxGui*&)’
src/UserPositionBehaviour.h:15: note: candidates are: UserPositionBehaviour::UserPositionBehaviour(Kinect*, ofxGui*, ofTrueTypeFont*)
src/UserPositionBehaviour.h:13: note:                 UserPositionBehaviour::UserPositionBehaviour(const UserPositionBehaviour&)

eh?? hei, what is happening? i'm passing pointers, not *& (that i don't event know how to read)

some advice?

i've tried to replicate the error with a simple case builds only on couts but there are no problems so mayebe there is some error hidden somewhereelse..

nkint
  • 11,513
  • 31
  • 103
  • 174
  • 3
    The code you're showing us shows a two-argument constructor; the error message says there's a three-argument one and a one-argument one. Something is not right here -- maybe you could show us the real code? – Ernest Friedman-Hill May 24 '12 at 13:50
  • There does not appear to be a constructor that accepts two arguments. – hmjd May 24 '12 at 13:50
  • 1
    Is it possible that you're including some header containing a different version of `UserPositionBehaviour` than the one you're expecting? – molbdnilo May 24 '12 at 13:54
  • sorry my mistake, i tried to simplify the code in the question, by the way i've tried to remove some arguments and the problem persists – nkint May 24 '12 at 14:11

3 Answers3

3

The code that causes the error passes three arguments (not two as you think), and it has the last two in the wrong order. You must be looking at the wrong version of the source files, or something like that.

Check for silly things like out-of-date copies of src/UserPositionBehaviour.h and src/App.cpp lying around, that you might be looking at instead of looking at the version the compiler is actually compiling. Or maybe you're using pre-compiled headers, and something has gone wrong there.

The error message for a not-found function will usually look like that. The Foo *& is type "reference to pointer to Foo", and it just means that your argument expression is an lvalue pointer-to-Foo. That call could match a function that takes a pointer by value, or a function that takes a pointer by reference. The compiler hasn't found either, but it has to pick something for the error message, and your compiler picks that one. If your call contained the argument expression device+0 instead of device, then it would not be eligible to pass by non-const reference (because the result of device+0 is a temporary), and the error message wouldn't have the &.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
3

According to the error message, you're calling the constructor with three arguments, not two, and you've got the last two the wrong way round.

If that's the real error message, then your code probably looks like:

UserPositionBehaviour = new UserPositionBehaviour(device, font, controls);
//                                                        ^^^^  ^^^^^^^^

and should be:

UserPositionBehaviour = new UserPositionBehaviour(device, controls, font);
//                                                        ^^^^^^^^  ^^^^

If your code really does look like what you've posted, and gives that error message, then something really weird is happening; in that case, please post a complete compilable example so we can investigate further.

You can ignore the extra &s in gcc's error message: it's a slightly odd way of saying that it's looking for functions that take their arguments by either value or reference.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

The code should compile if you truly have the constructor

UserPositionBehaviour(Kinect * device, Gui * controls);

defined, which, according to the compiler, you don't:

src/UserPositionBehaviour.h:15: note: candidates are: UserPositionBehaviour::UserPositionBehaviour(Kinect*, ofxGui*, ofTrueTypeFont*) src/UserPositionBehaviour.h:13: note:
UserPositionBehaviour::UserPositionBehaviour(const UserPositionBehaviour&)

The *& simply means you pass the pointer by reference - i.e. it can be modified inside the constructor.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625