c2054未定义基类_c++ - 错误C2504:基类未定义 - 堆栈内存溢出

在尝试创建Player类并将其声明为Mob的派生类时,遇到了C2504错误。Player类在包含Mob类的头文件中定义,但编译器表示'Mob'基类未定义。问题可能是由于头文件包含顺序或前向声明导致的循环依赖。寻求解决方案。
摘要由CSDN通过智能技术生成

我之前多次遇到过这个错误并最终找到了解决方案,但是这个让我难过。 我有一个由'Player'继承的类'Mob'。 这是Mob.h:

#pragma once

#include "PlayState.h"

#include "OmiGame/OmiGame.h"

#include "resources.h"

class PlayState;

class Mob

{

private:

int frames;

int width;

int height;

int time;

sf::Texture textureL;

sf::Texture textureR;

Animation animationL;

Animation animationR;

AnimatedSprite sprite;

bool moveLeft;

bool moveRight;

bool facingRight;

public:

void createMob(std::string l, std::string r, int frames, int width, int height, int time, int x, int y);

void updateMob(omi::Game *game, PlayState *state);

void drawMob(sf::RenderTarget &target);

void setLeft(bool b) { moveLeft = b; }

void setRight(bool b) { moveRight = b; }

bool isLeft() { return moveLeft; }

bool isRight() { return moveRight; }

sf::Vector2f getPosition() { return sprite.getPosition(); }

};

这是Player.h,截至目前它非常简单:

#pragma once

#include "OmiGame/OmiGame.h"

#include "PlayState.h"

#include "Mob.h"

#include "resources.h"

class PlayState;

class Mob;

const int playerFrames = 8;

const int playerWidth = 16;

const int playerHeight = 48;

const int playerTime = 50;

const int playerX = 200;

const int playerY = 200;

class Player : public Mob

{ //the error occurs at this line//

public:

Player();

void update(omi::Game *game, PlayState *state);

void draw(sf::RenderTarget &target);

};

并且,正如您可能猜到的,这是错误:

error C2504: 'Mob' : base class undefined player.h

我有前锋宣布的暴徒,我希望修复任何循环依赖。 请有人帮帮我吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值