#1
by keito94 » 8年前
どうもkeito940です。Platinumというマップエディターを使って、アクションゲームのためにマップを読み出すプログラムを作ってそれをコンパイルしようとしたところ、main.cppで何故か「C2512 'CCharMoveAndMap': クラス、構造体、共用体に既定のコンストラクターがありません。」と出ました。
ソースコードをあげますので、どこに原因があるかを教えて下さい。
CharMove.cpp
コード:
#include "DxLib.h"
#include "CharMove.h"
#include "fmfmap.h"
CFmfMap MapObj;
CCharMoveAndMap::CCharMoveAndMap(POINT pt[], float clx, float crx, float cty, float cby, int coltype)
: Clx(clx), Crx(crx), Cty(cty), Cby(cby),ColType(coltype)
{
Init();
for (int i = 0; i < 8; i++) {
mPt[i].x = pt[i].x;
mPt[i].y = pt[i].y;
}
}
int CCharMoveAndMap::MapLoad(const char* file_name, int stage_num) {
MapBitCount = MapObj.GetLayerBitCount() == 8 ? 16 : 256;
if (!MapObj.Open(file_name)) {
return -1;
}
BYTE* layer = (BYTE*)MapObj.GetLayerCount();
if (layer == NULL) {
return -1;
}
return 0;
}
void CCharMoveAndMap::Init() {
ZeroMemory(mPt, sizeof(mPt));
}
POINT CCharMoveAndMap::CheckMap(int x, int y) {
POINT pt[] = {
{ x + mPt[0].x, y + mPt[0].y },//左上
{ x + mPt[1].x, y + mPt[1].y },//上真ん中
{ x + mPt[2].x, y + mPt[2].y },//右上
{ x + mPt[3].x, y + mPt[3].y },//左真ん中
{ x + mPt[4].x, y + mPt[4].y },//右真ん中
{ x + mPt[5].x, y + mPt[5].y },//左下
{ x + mPt[6].x, y + mPt[6].y },//下真ん中
{ x + mPt[7].x, y + mPt[7].y },//右下
};
POINT res = { x, y };
DWORD cwidth = MapObj.GetChipWidth();
DWORD cheight = MapObj.GetChipHeight();
for (int i = 0; i < 8; i++) {
int index = MapObj.GetValue(1, pt[i].x / MapCell, pt[i].y / MapCell);
int src_x = (index % MapBitCount) * cwidth;
int src_y = (index / MapBitCount) * cheight;
if (src_x == 0 && src_y == 0) // 取得したindexが壁だったら
{
res.x = pt[i].x / MapCell; // 壁の座標を代入
res.y = pt[i].y / MapCell;
return res; // 壁の座標を返す
}
}
res.x = -1;
res.y = -1;
return res;
}
void CCharMoveAndMap::MapDraw() {
DWORD swidth = MapObj.GetMapWidth();
DWORD sheight = MapObj.GetMapHeight();
DWORD cwidth = MapObj.GetChipWidth();
DWORD cheight = MapObj.GetChipHeight();
DWORD i, j;
int index, src_x, src_y;
for (i = 0; i < sheight / MapCell; i++) {
for (j = 0; j = swidth / MapCell; i++) {
index = MapObj.GetValue(0, i, j);
src_x = (index % MapBitCount) * cwidth;
src_y = (index / MapBitCount) * cheight;
}
}
}
CharMove.h
コード:
#pragma once
//マップチップ
const int MapCell = 16;
class CCharMoveAndMap {
float Clx, Crx, Cty, Cby;
POINT mPt[8];
int ColType;
int MapBitCount;
public:
CCharMoveAndMap(POINT pt[], float clx, float crx, float cty, float cby,int coltype);
int MapLoad(const char* file_name, int stage_num);
void Init();
POINT CheckMap(int x, int y);
void MapDraw();
};
Player.h
コード:
//プレイヤーのクラスを宣言する。
class CPlayer {
//変数を宣言する。
float X, Y;
float VX, VY;
int CX, CY;
char DashB, DashR, Dash;
int Dir, DashCnt,dir;
int Input, EdgeInput;
int Graph;
//関数を宣言する。
public:
//プレイヤーの初期化。
void Init(void);
//プレイヤーの動きを計算。
void Update(void);
//プレイヤーの描画。
void Draw(void);
//プレイヤーの終了処理。
void Fin(void);
};
Main.cpp
コード:
#include "Main.h"
#include "Player.h"
#include "CharMove.h"
int Time;
CPlayer Player;
CGameMain Main;
CCharMoveAndMap CharMoveMap;
int CGameMain::Init() {
ChangeWindowMode(TRUE), SetGraphMode(320, 240, 32);
//DXライブラリの初期化エラーが発生したときに終了。
if (DxLib_Init() == -1) { return -1; }
Time = GetNowCount();
SetDrawScreen(DX_SCREEN_BACK);
SetWaitVSyncFlag(FALSE);
Player.Init();
return 0;
}
void CGameMain::Main() {
Time = GetNowCount();
//1/60秒立つまで待つ
while(GetNowCount()-Time<1000/60){}
Player.Update();
Player.Draw();
}
void CGameMain::Fin() {
Player.Fin();
DxLib_End();
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
Main.Init();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
Main.Main();
}
Main.Fin();
return 0;
}
Main.h
コード:
class CGameMain {
public:
int Init();
void Main();
void Fin();
};
どうもkeito940です。Platinumというマップエディターを使って、アクションゲームのためにマップを読み出すプログラムを作ってそれをコンパイルしようとしたところ、main.cppで何故か「C2512 'CCharMoveAndMap': クラス、構造体、共用体に既定のコンストラクターがありません。」と出ました。
ソースコードをあげますので、どこに原因があるかを教えて下さい。
CharMove.cpp
[code]
#include "DxLib.h"
#include "CharMove.h"
#include "fmfmap.h"
CFmfMap MapObj;
CCharMoveAndMap::CCharMoveAndMap(POINT pt[], float clx, float crx, float cty, float cby, int coltype)
: Clx(clx), Crx(crx), Cty(cty), Cby(cby),ColType(coltype)
{
Init();
for (int i = 0; i < 8; i++) {
mPt[i].x = pt[i].x;
mPt[i].y = pt[i].y;
}
}
int CCharMoveAndMap::MapLoad(const char* file_name, int stage_num) {
MapBitCount = MapObj.GetLayerBitCount() == 8 ? 16 : 256;
if (!MapObj.Open(file_name)) {
return -1;
}
BYTE* layer = (BYTE*)MapObj.GetLayerCount();
if (layer == NULL) {
return -1;
}
return 0;
}
void CCharMoveAndMap::Init() {
ZeroMemory(mPt, sizeof(mPt));
}
POINT CCharMoveAndMap::CheckMap(int x, int y) {
POINT pt[] = {
{ x + mPt[0].x, y + mPt[0].y },//左上
{ x + mPt[1].x, y + mPt[1].y },//上真ん中
{ x + mPt[2].x, y + mPt[2].y },//右上
{ x + mPt[3].x, y + mPt[3].y },//左真ん中
{ x + mPt[4].x, y + mPt[4].y },//右真ん中
{ x + mPt[5].x, y + mPt[5].y },//左下
{ x + mPt[6].x, y + mPt[6].y },//下真ん中
{ x + mPt[7].x, y + mPt[7].y },//右下
};
POINT res = { x, y };
DWORD cwidth = MapObj.GetChipWidth();
DWORD cheight = MapObj.GetChipHeight();
for (int i = 0; i < 8; i++) {
int index = MapObj.GetValue(1, pt[i].x / MapCell, pt[i].y / MapCell);
int src_x = (index % MapBitCount) * cwidth;
int src_y = (index / MapBitCount) * cheight;
if (src_x == 0 && src_y == 0) // 取得したindexが壁だったら
{
res.x = pt[i].x / MapCell; // 壁の座標を代入
res.y = pt[i].y / MapCell;
return res; // 壁の座標を返す
}
}
res.x = -1;
res.y = -1;
return res;
}
void CCharMoveAndMap::MapDraw() {
DWORD swidth = MapObj.GetMapWidth();
DWORD sheight = MapObj.GetMapHeight();
DWORD cwidth = MapObj.GetChipWidth();
DWORD cheight = MapObj.GetChipHeight();
DWORD i, j;
int index, src_x, src_y;
for (i = 0; i < sheight / MapCell; i++) {
for (j = 0; j = swidth / MapCell; i++) {
index = MapObj.GetValue(0, i, j);
src_x = (index % MapBitCount) * cwidth;
src_y = (index / MapBitCount) * cheight;
}
}
}
[/code]
CharMove.h
[code]
#pragma once
//マップチップ
const int MapCell = 16;
class CCharMoveAndMap {
float Clx, Crx, Cty, Cby;
POINT mPt[8];
int ColType;
int MapBitCount;
public:
CCharMoveAndMap(POINT pt[], float clx, float crx, float cty, float cby,int coltype);
int MapLoad(const char* file_name, int stage_num);
void Init();
POINT CheckMap(int x, int y);
void MapDraw();
};
[/code]
Player.h
[code]
//プレイヤーのクラスを宣言する。
class CPlayer {
//変数を宣言する。
float X, Y;
float VX, VY;
int CX, CY;
char DashB, DashR, Dash;
int Dir, DashCnt,dir;
int Input, EdgeInput;
int Graph;
//関数を宣言する。
public:
//プレイヤーの初期化。
void Init(void);
//プレイヤーの動きを計算。
void Update(void);
//プレイヤーの描画。
void Draw(void);
//プレイヤーの終了処理。
void Fin(void);
};
[/code]
Main.cpp
[code]
#include "Main.h"
#include "Player.h"
#include "CharMove.h"
int Time;
CPlayer Player;
CGameMain Main;
CCharMoveAndMap CharMoveMap;
int CGameMain::Init() {
ChangeWindowMode(TRUE), SetGraphMode(320, 240, 32);
//DXライブラリの初期化エラーが発生したときに終了。
if (DxLib_Init() == -1) { return -1; }
Time = GetNowCount();
SetDrawScreen(DX_SCREEN_BACK);
SetWaitVSyncFlag(FALSE);
Player.Init();
return 0;
}
void CGameMain::Main() {
Time = GetNowCount();
//1/60秒立つまで待つ
while(GetNowCount()-Time<1000/60){}
Player.Update();
Player.Draw();
}
void CGameMain::Fin() {
Player.Fin();
DxLib_End();
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
Main.Init();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
Main.Main();
}
Main.Fin();
return 0;
}
[/code]
Main.h
[code]
class CGameMain {
public:
int Init();
void Main();
void Fin();
};
[/code]