python vector初始化_在C++ 类中初始化vector失败的问题?

初学者在C++编程中尝试创建一个贪吃蛇游戏,遇到在类中使用vector初始化蛇身体的问题。错误发生在尝试用`make_pair(make_pair(10, 10), "●")`初始化`vector<pair<int, int>, string>>`类型的`snakebody`时,编译器报错C2664,无法将`pair<pair<int, int>, const char*>`转换为`const std::allocator<_ty> &`。" 134152765,7337247,程序员通过机器学习与AI实现财富自由,"['大数据', '人工智能', '语言模型', 'Python', 'Java']
摘要由CSDN通过智能技术生成

初学C++,我试着写一个贪吃蛇游戏,代码如下:

#include

#include

#include

#include

#include

#include

using namespace std;

class Snake

{

friend void displaySnake(Snake &s);

public:

using ssbody = pair, string>;

Snake() = default;

vector body() const { return snakebody; }

private:

int lengh=1; //蛇的长度

vector snakebody{make_pair(make_pair(10, 10), "●")}; //蛇的位置和符号

};

void gotoxy(int x, int y)

{

HANDLE h;//句柄,对象的索引

COORD c;//结构体,坐标值

c.X = x;

c.Y = y;

h = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(h, c);

}

void displaySnake(Snake &s) //打印蛇

{

for (auto &c : s.snakebody){

gotoxy(c.fir

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值