'GameObject': no appropriate default constructor available
我正在尝试创建一个游戏,游戏对象是从瓷砖,玩家,敌人和墙壁的一切。我正在尝试让我的类角色(父级到两个以上的类玩家和敌人)到基类游戏对象。当我尝试为字符创建构造函数时,在character.cpp文件中得到了c2512错误。有人能指出我可能做错了什么吗?事先谢谢。
字符.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #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 #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 |
游戏对象.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #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); |
号
字符.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #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 #include <string> #include <vector> using namespace std; void Character::attack(vector<Character *>&characters) {}; Character::Character() { }; Character::~Character() {}; |
1 | Character::Character() {}; |
等于
1 | Character::Character() : GameObject() {}; |
号
由于
1 2 3 4 5 | Character(Mesh* mesh, Shader* shader, InputController *input, Vector3 position, Texture* texture); |
并按以下方式实施:
1 2 3 4 5 | Character::Character(Mesh* mesh, Shader* shader, InputController *input, Vector3 position, Texture* texture) : GameObject(mesh, shader, input, position, texture) {} |
。
您的
因为在
如果没有为类