【发布时间】:2017-08-15 10:36:40
【问题描述】:
我正在尝试创建一个游戏,其中 GameObject 包含瓷砖、玩家、敌人和墙壁的所有内容。我正在尝试将我的类 Character(另外两个类 Player 和 Enemy 的父类)添加到基类 GameObject。当我尝试为 Characters 创建构造函数时,在 Character.cpp 文件中出现 C2512 错误。谁能指出我做错了什么?提前致谢。
Characters.h
#ifndef CHARACTERS_H
#define CHARACTERS_H
#include <cstdlib>
#include <ctime> /*cstdlib and ctime are used to help with the pseudo randomness for events*/
#include <cstdio> /*allows remove function*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <array>
#include <string>
#include <vector>
#include "GameObject.h"
using namespace std;
class Character : public GameObject{
public:
Character();
~Character();
virtual void attack(vector<Character *>&characters) = 0;
void set_values(string nam, int hp, int str, int mag) {
name = nam;
health = hp;
strength = str;
magic = mag;
};
string name;
int health;
int strength;
int magic;
};
#endif
GameObject.h
#ifndef GAMEOBJECCT_H
#define GAMEOBJECT_H
#include "Direct3D.h"
#include "Mesh.h"
#include "InputController.h"
class GameObject {
protected:
Vector3 m_position;
float m_rotX, m_rotY, m_rotZ;
float m_scaleX, m_scaleY, m_scaleZ; //Not really needed for A1.
//Used for rendering
Matrix m_world;
Mesh* m_mesh;
Texture* m_texture;
Shader* m_shader;
InputController* m_input; //Might have enemies who react to player input.
float m_moveSpeed;
float m_rotateSpeed;
public:
//Constructor
GameObject(Mesh* mesh, Shader* shader, InputController *input, Vector3 position, Texture* texture);
~GameObject();
void Update(float timestep);
void Render(Direct3D* renderer, Camera* cam);
Characters.cpp
#include "Characters.h"
#include <cstdlib>
#include <ctime> /*cstdlib and ctime are used to help with the pseudo randomness for events*/
#include <cstdio> /*allows remove function*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <array>
#include <string>
#include <vector>
using namespace std;
void Character::attack(vector<Character *>&characters) {};
Character::Character() {
};
Character::~Character() {};
【问题讨论】:
标签: c++ inheritance parent-child default-constructor