初心者の汚いコードで、関係のないコメントもあってすいませんm(_ _)m
//graphic.h
#include "graphic.h"
#include "Dxlib.h"
#include "define.h"
Graphic graphic;
void makedummy(){
dummygr = MakeGraph(2, 2);
}
void GrSet::update(){
if (animate&&animeframe){//draw==0でも進行
animecnt++;
if (animecnt%animeframe==0){
it++;
if (it == img.end()){
it = img.begin();
if (!loop)draw = 0;
}
}
}
}
int GrSet::getgr(){
if (draw){
return(*it);
}
else return(dummygr);
}
void Graphic::load(){
static bool isloaded = 0;
if (isloaded==1)return;
isloaded = 1;
makedummy();
int handle[64];
LoadDivGraph("img/gr.png", 64, 4, 16, 8, 8, handle, 1);
player.getnormal().setgr(handle,1);
player.getdead().setgr(handle + 1, 3);
player.getdead().setloop(0);
shot.getnormal().setgr(handle+4, 2);
shot.getdead().setgr(handle + 6, 2);
shot.getdead().setloop(0);
{ GrSet enenormal;
GrSet enedead;
enedead.setloop(0);
enemy.resize(ENETYPE);
for (int i = 0; i < ENETYPE; i++){
enenormal.setgr(handle + 8 + 4 * i, 2);
enedead.setgr(handle + 8 + 4 * i + 2, 2);
enemy[i].getnormal() = enenormal;
enemy[i].getdead() = enedead;}
}
GrSet bulletnormal;
GrSet bulletdead;
bulletdead.setloop(0);
bulletdead.setdraw(0);
bullet.resize(ENETYPE);
for (int i = 0; i < ENETYPE; i++){
bulletnormal.setgr(handle + 32 + 2 * i, 2);
bulletdead.setgr(handle+63, 1);//dummy
bullet[i].getnormal() =bulletnormal;
bullet[i].getdead() = bulletdead;
}
}
//obj.h
#pragma once
#include "graphic.h"
#include <cmath>
#include "DxLib.h"
class GrSet;
class GrSetSet;
class Graphic;
struct Pos;
class Obj;
struct Pos{
float x, y;
Pos(){ x = 0, y = 0; }
Pos(float X, float Y){ x = X; y = Y; }
Pos operator+(const Pos& p){ Pos a(x + p.x, y + p.y); return a; }
Pos operator-(const Pos& p){ Pos a(x - p.x, y - p.y); return a; }
Pos operator*(const float& f){ Pos a(x*f, y*f); return a; }
Pos operator/(const float& f){ Pos a(x/f, y/f); return a; }
Pos & operator+=(const Pos& p){ x += p.x, y += p.y; return *this; }
Pos & operator-=(const Pos& p){ x -= p.x, y -= p.y; return *this; }
Pos & operator*=(const float& f){ x *= f, y *= f; return *this; }
Pos & operator/=(const float& f){ x /= f, y /= f; return *this; }
float norm(){ return(sqrt(x*x + y*y)); }
float angle(){ return(atan2(y, x)); }
Pos& normalize(){ if (abs(norm())<0.00001F)*this /= norm(); return *this; }
};
Pos makepos(float x, float y);
class Obj{
bool flag;
Pos pos,speed;
GrSetSet gr;//←ここだけにエラー!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public:
};
class Player:public Obj{
void init();
void update();
};
不思議なのは、問題の行GrSetSet gr;をコメントアウトすると正常にコンパイルされることです。(graphic.hのGraphicでもGrSetSetを使っているのに)
この症状は、循環参照が起きると起こる、と聞きましたが、見つかりません。
原因がわかる方、いらっしゃったらお願いします。