抽象クラスをオーバーライドしたらエラーが出る
Posted: 2012年4月14日(土) 09:50
抽象クラスをオーバーライドしたら、ちゃんと定義しているのに、エラーがでます。
1>d:\visual studio 2010\projects\shooting\shooting\cplayer.h(94): error C2259: 'Cplayer_normalbullet' : 抽象クラスをインスタンス化できません。
1> 次のメンバーが原因です:
1> 'bool Cplayer_bullet::hitchk(C_2d_circle)' : は抽象型です
1> d:\visual studio 2010\projects\shooting\shooting\cplayer.h(10) : 'Cplayer_bullet::hitchk' の宣言を確認してください。
1>d:\visual studio 2010\projects\shooting\shooting\cplayer.h(94): error C2259: 'Cplayer_normalbullet' : 抽象クラスをインスタンス化できません。
1> 次のメンバーが原因です:
1> 'bool Cplayer_bullet::hitchk(C_2d_circle)' : は抽象型です
1> d:\visual studio 2010\projects\shooting\shooting\cplayer.h(10) : 'Cplayer_bullet::hitchk' の宣言を確認してください。
#pragma once
extern int key;
extern Cpicture player_pic;
extern Cpicture player_bullet_pic;
inline bool chk_in_view(C_2d_circle in_cir);
class Cplayer_bullet{
public:
virtual bool proc(void)=0;//返り値trueの時削除
virtual bool hitchk(C_2d_circle in_cir)=0;
virtual void draw(void)=0;
};
class Cplayer_normalbullet : public Cplayer_bullet{
public:
Cplayer_normalbullet(const C_2d_vector& in_pos,const C_2d_vector& in_vec);
bool proc(void);
bool hitchk(const C_2d_circle& in_cir);
void draw(void);
private:
C_2d_circle cir;
C_2d_vector vec;
};
Cplayer_normalbullet::Cplayer_normalbullet(const C_2d_vector& in_pos,const C_2d_vector& in_vec){
cir.pos=in_pos;
cir.r=7;
vec=in_vec;
return;
}
bool Cplayer_normalbullet::proc(void){
cir.pos+=vec;
if(chk_in_view(cir)) return false;
return true;
}
bool Cplayer_normalbullet::hitchk(const C_2d_circle& in_cir){
if(hitchk_circle_circle(cir,in_cir)) return true;
return false;
}
void Cplayer_normalbullet::draw(void){
player_bullet_pic.center_draw(cir.pos);
return;
}
class Cplayer{
public:
Cplayer();
//~Cplayer();
void proc();
void draw();
C_2d_circle get_circle();
bool hitchk_playerbullet(const C_2d_circle& in_cir);
private:
C_2d_circle cir;
list<Cplayer_bullet*> p_bullet_list;
};
Cplayer::Cplayer(){
cir.pos=To_C_2d_vector(400,400);
cir.r=20;
//pic=player_pic;
return;
}
void Cplayer::proc(void){
C_2d_vector mov;
bool x_flag=false,y_flag=false;
if(key&PAD_INPUT_UP){
mov.y-=7;
y_flag=true;
}
if(key&PAD_INPUT_DOWN){
mov.y+=7;
y_flag=true;
}
if(key&PAD_INPUT_RIGHT){
mov.x+=7;
x_flag=true;
}
if(key&PAD_INPUT_LEFT){
mov.x-=7;
x_flag=true;
}
if(x_flag&&y_flag) mov/=sqrt_2;
C_2d_vector before_pos=cir.pos;
cir.pos+=mov;
if(((cir.pos.x<cir.r)||(cir.pos.x>scr_x-cir.r)||(cir.pos.y<cir.r)||(cir.pos.y>scr_y-cir.r))) cir.pos=before_pos;
static int bullet_timer;
bullet_timer++;
if((key&PAD_INPUT_1)&(bullet_timer>15)){
p_bullet_list.push_front(new Cplayer_normalbullet(cir.pos,To_C_2d_vector(0,15)));
bullet_timer=0;
}
auto itr=p_bullet_list.begin();
while(itr!=p_bullet_list.end()){
if((*(*itr)).proc()){
delete (*itr);
itr=p_bullet_list.erase(itr);
}else{
itr++;
}
}
return;
}
void Cplayer::draw(void){
auto itr=p_bullet_list.begin();
while(itr!=p_bullet_list.end()){
(*(*itr)).draw();
itr++;
}
player_pic.center_draw(cir.pos);
return;
}
C_2d_circle Cplayer::get_circle(void){
return cir;
}
bool Cplayer::hitchk_playerbullet(const C_2d_circle& in_cir){
auto itr=p_bullet_list.begin();
while(itr!=p_bullet_list.end()){
if((*(*itr)).hitchk(in_cir)){
delete (*itr);
p_bullet_list.erase(itr);
return true;
}else{
itr++;
}
}
return false;
}