Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.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++_Grid_C++11 - Fatal编程技术网

C++ 如何从c+;中的跟踪器类创建跟踪器对象+;?

C++ 如何从c+;中的跟踪器类创建跟踪器对象+;?,c++,grid,c++11,C++,Grid,C++11,我正在做一个简单的跳棋游戏,并设置了一个网格系统,我只想开始设置下面的类中显示的参数 #include <iostream> #include <vector> using namespace std; class Tracker { private: int type_; int positionx_; int positiony_; int checkID_; public: Tracker(int type, int po

我正在做一个简单的跳棋游戏,并设置了一个网格系统,我只想开始设置下面的类中显示的参数

#include <iostream>
#include <vector>

using namespace std;

class Tracker {
private:
    int type_;
    int positionx_;
    int positiony_;
    int checkID_;
public:
    Tracker(int type, int positionx, int positiony, int checkID) : type_(type), positionx_(positionx), positiony_(positiony), checkID_(checkID)
    {

    }
    void setType(int type) {
        type_ = type;
    }

    void setPosX(int posx) {
        positionx_ = posx;
    }

    void setPosY(int posy) {
        positiony_ = posy;
    }

    void setCheckID(int ID) {
        checkID_ = ID;
    }

    int getType(int ID) {
        return type_;
    }

    int getPosX(int ID) {
        return positionx_;
    }

    int getPosY(int ID) {
        return positiony_;
    }

    int getCheckID(int positionx, int positiony) {
        return checkID_;
    }

    bool AddPeice(int positionx, int positiony, int checkID) {

    }

};
#包括
#包括
使用名称空间std;
类跟踪器{
私人:
int型;
int位置x;
int位置y;
int-checkID;
公众:
跟踪器(内部类型、内部位置X、内部位置Y、内部检查ID):类型(类型)、位置X(位置X)、位置Y(位置Y)、检查ID(检查ID)
{
}
void setType(int类型){
类型=类型;
}
void setPosX(int posx){
位置x=位置x;
}
void setPosY(int posy){
位置y=位置y;
}
void setCheckID(int-ID){
checkID_uuid=ID;
}
int getType(int ID){
返回类型;
}
intgetposx(intid){
返回位置x;
}
int getPosY(int ID){
返回位置y;
}
int getCheckID(int positionx,int positiony){
返回checkID;
}
布尔地址(内部位置X、内部位置Y、内部检查ID){
}
};
我只是试着在我的主类中设置每个片段的位置和类型,以便以后能够操作它们。错误是

错误(活动)类“跟踪器”不存在默认构造函数

这是在我将每件作品设置为如下所示后发生的:

vector<Tracker> setup;
Tracker checker;


checker.setType(1);
    checker.setCheckID(20 + i);
    checker.setPosX(xx);
    checker.setPosY(yy);
    setup.push_back(checker);
向量设置;
跟踪器检测器;
checker.setType(1);
checker.setCheckID(20+i);
checker.setPosX(xx);
检查器设置位置(yy);
设置。推回(检查器);
为了在其他类中使用跟踪器对象,我需要向我的跟踪器类添加什么?

您应该使用:

Tracker checker(1, xx, yy, 20 + i);
而不是:

Tracker checker;
checker.setType(1);
checker.setCheckID(20 + i);
checker.setPosX(xx);
checker.setPosY(yy);
这是因为
Tracker
类拥有的唯一构造函数是:

Tracker(int type, int positionx, int positiony, int checkID)
所以这句话:

Tracker checker;
导致错误的原因:

Error (active) no default constructor exists for class "Tracker"
此外,由于要将
跟踪器
添加到向量中,如果您可以访问以下功能,则可以使用
emplace\u back

std::vector<Tracker> setup;
setup.emplace_back(1, xx, yy, 20 + i);
std::向量设置;
设置。向后放置(1,xx,yy,20+i);
这可能比先构建
跟踪器
,然后使用
推回
更有效。您应该使用:

Tracker checker(1, xx, yy, 20 + i);
而不是:

Tracker checker;
checker.setType(1);
checker.setCheckID(20 + i);
checker.setPosX(xx);
checker.setPosY(yy);
这是因为
Tracker
类拥有的唯一构造函数是:

Tracker(int type, int positionx, int positiony, int checkID)
所以这句话:

Tracker checker;
导致错误的原因:

Error (active) no default constructor exists for class "Tracker"
此外,由于要将
跟踪器
添加到向量中,如果您可以访问以下功能,则可以使用
emplace\u back

std::vector<Tracker> setup;
setup.emplace_back(1, xx, yy, 20 + i);
std::向量设置;
设置。向后放置(1,xx,yy,20+i);
这可能比先构造
跟踪器
,然后使用
推回
更有效