Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么类函数的参数会出错&引用;“调用”没有匹配的函数;C++;_C++ - Fatal编程技术网

C++ 为什么类函数的参数会出错&引用;“调用”没有匹配的函数;C++;

C++ 为什么类函数的参数会出错&引用;“调用”没有匹配的函数;C++;,c++,C++,错误:调用“Player::setX(int&,bool&)”时没有匹配的函数 大体上: //player pc.setX(pc.x, *actions); //actions is an arr of input possibilities. pc.setY(pc.y, *actions); 在player.h中: public: int x = 1, y = 1; int setY (int y, int *actions); int setX (i

错误:调用“Player::setX(int&,bool&)”时没有匹配的函数

大体上:

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

  public:
  int x = 1, y = 1;
  int setY (int y, int *actions);
  int setX (int x, int *actions);
第二个问题:是否可以将x/y作为结构而不是单独传递

所有必需的代码:

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

不要将变量类型作为注释。在代码中按原样包含声明。做一个决定。看起来您正在尝试传递一个
bool
而不是
int*
。欢迎这样做,向我们展示更多的代码(至少是动作声明),我们可以帮助您。
actions
是一个
bool[]
数组,其中
*actions
访问数组中的第一个
bool
。您试图传递一个
bool
,其中需要
int*
指针,这就是错误告诉您的。你到底想完成什么?至于x/y,当然你可以传递一个
struct
,你为什么不这样想呢?
bool
数组没有
int
地址。如果你试图将数组本身传递给函数,那么将参数从
int*
更改为
bool*
,然后在调用时将
*操作
更改为仅
操作
。然后让你自己解释一下指针是如何工作的,这并不能回答问题。OP:s代码中的主要问题是,他/她将
bool
而不是
int*
传递给
actions
参数。
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);