简体   繁体   中英

why am i getting error for parameters of class function? “no matching function for call” C++

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 //
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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM