0

error: no matching function for call to 'Player::setX(int&, bool&)'

in main:

    //player
    pc.setX(pc.x, *actions); //actions is an arr of input possibilities.
    pc.setY(pc.y, *actions);

in player.h:

  public:
  int x = 1, y = 1;
  int setY (int y, int *actions);
  int setX (int x, int *actions);

secondary question: is it possible to pass x/y as a struct instead of individually?

all the code that should be necessary afaik:

    bool actions[10]; //"up", "down", "left", "right", "skill1", "skill2", "skill3", "skill4", "skill5", "interact",
Player pc; //object creation

//player
pc.setX(pc.x, *actions);
pc.setY(pc.y, *actions);



#ifndef PLAYER_H
#define PLAYER_H
  class Player
  {
    public:
      int x = 1, y = 1;
      int setY (int y, int *actions);
      int setX (int x, int *actions);
    private:

  };
#endif //
  • 2
    Don't put the variable type as a comment. Include the declaration as it is in the code. Make a [mcve]. It looks like you're trying to pass a `bool` instead of an `int*`. – Ted Lyngmo May 11 '20 at 18:50
  • Welcome to SO, Show us a bit more code (the declaration of actions at least) and we can help you. – Elemental May 11 '20 at 18:56
  • 2
    `actions` is a `bool[]` array, where `*actions` accesses the 1st `bool` in the array. You are trying to pass a single `bool` where an `int*` pointer is expected, that is what the error is telling you. What are you trying to accomplish exactly? As for x/y, of course you can pass a `struct` instead, why would you think otherwise? – Remy Lebeau May 11 '20 at 18:57
  • im trying to pass the int address of the bool array. also I tried using a struct early and could figure it out. Guess i'll revisit that – lemonylime May 11 '20 at 18:59
  • 2
    There is no `int` address for a `bool` array. – Ted Lyngmo May 11 '20 at 18:59
  • an address is always an int isnt it? – lemonylime May 11 '20 at 19:00
  • 2
    If you are trying to pass the array itself to the functions, then change the parameters from `int*` to `bool*`, and then change `*actions` to just `actions` when calling them. And then get yourself [a good C++ book](https://stackoverflow.com/questions/388242/) that explains how pointers actually work. – Remy Lebeau May 11 '20 at 19:01
  • An address is an integer, but rarely an `int`. If you managed to convert (cast) the `bool[]` to an `int*` your function would be in trouble. It'd try to read `int` values from the decayed array which is usually much larger than `bool` values. You'd probably end up reading 4 or 8 `bool`s as one `int`. – Ted Lyngmo May 11 '20 at 19:06

1 Answers1

-1
Yes you can pass both variable in a struct as:

        typedef struct { int x, int y}sXYInfo;
        class Player
        { public:
          sXYInfo m_sxy;
          int setXY (sXYInfo sxy , int *actions);
         };
and when calling use below, as you are passing array as a pointer:
    pc.setXY(pc.m_sxy, actions);
user9559196
  • 157
  • 6
  • This does not answer the question. The main problem in OP:s code is that he/she passes a `bool` instead of an `int*` to the `actions` argument. – Ted Lyngmo May 11 '20 at 20:47