我的代码中出现了两次这种情况,我不确定为什么它抱怨我有一个头文件“Scene.h”:
#pragma once
#include <iostream>
#include <string>
#include "Image.h"
#include "InteractiveObject.h"
using namespace std;
class Scene
{
public:
int id;
string title;
Image* backgroundImage;
InteractiveObject interactiveObjects[ 1 ];
D3DXVECTOR3 pos;
Scene( int id_, string title_, Image* backgroundImage_ )
:
id( id_ ),
title( title_ ),
backgroundImage( backgroundImage_ )
{
this->pos.x = 0.0f;
this->pos.y = 0.0f;
this->pos.z = 0.0f;
}
};
我有另一个名为“InteractiveObject.h”的文件:
#pragma once
#include <iostream>
#include <string>
#include "Image.h"
enum { CHARACTER, OBJECT };
class InteractiveObject
{
public:
int id;
int type;
float x;
float y;
float z;
D3DXVECTOR3 pos;
string title;
Image* theImage;
InteractiveObject( int id_, string title_, Image* theImage_, int type, float x, float y, float z )
:
id( id_ ),
title( title_ ),
theImage( theImage_ )
{
this->pos.x = x;
this->pos.y = y;
this->pos.z = z;
}
};
我的智能感知抱怨有:
错误 1 错误 C2512: 'InteractiveObject' : 没有合适的默认构造函数可用 c:\users\james\documents\visual studio 2012\projects\game\game\scene.h 26 1 Game
考虑到两者都有默认构造函数的任何想法?
编辑:: - - - - -
好的,感谢这里的每个人,如果我这样做,我可以看到:;
InteractiveObject( int id_, string title_, Image* theImage_, int type_, float x_, float y_, float z_ )
:
id( id_ ),
title( title_ ),
theImage( theImage_ ),
type( type_ ),
x( x_ ),
y( y_ ),
z( z_ )
{
问题消失了。我不确定这是不是最好的方法,我肯定会在片刻后哭着回来。您能否投票选出您认为最简洁的答案?
我目前的要求是让场景包含在我的游戏构造函数中声明的一定数量的交互式对象,并迭代以绘制到屏幕上:
“游戏.cpp”:
Game::Game( HWND hWnd, Mouse &mouse )
:
gfx( hWnd ),
mouse( mouse )
{
gfx.d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
//--------------Scene 0---------------
scenes[ 0 ] = Scene( 0, "La barra de funk", new Image( gfx, "Images/Scene/Area/Bar/Background.jpg", 1024, 768, FALSE ) );
scenes[ 0 ].interactiveObjects[ 0 ] = new InteractiveObject( 0, "la rockola de muse", new Image( gfx, "Images/Scene/Area/Bar/InteractiveObjects/Jukebox.png", 428, 586, TRUE ), OBJECT, 300.0f, 200.0f, 1.0f );
};
Game::~Game()
{
// Delete scenes array
/*for( int a = 0; a < sizeof( scenes ) / sizeof( Scene ); a++ )
{
scenes[ a ] = NULL;
delete scenes[ a ];
}*/
};
void Game::Go()
{
gfx.Begin();
ComposeFrame();
gfx.End();
gfx.Present();
};
void Game::ComposeFrame()
{
for each ( Scene currentScene in scenes )
{
currentScene.backgroundImage->sprite->Begin( D3DXSPRITE_ALPHABLEND );
currentScene.backgroundImage->sprite->Draw( currentScene.backgroundImage->gTexture, NULL, NULL, ¤tScene.pos, 0xFFFFFFFF );
currentScene.backgroundImage->sprite->End();
for each ( InteractiveObject currentInteractiveObject in currentScene.interactiveObjects )
{
currentInteractiveObject.theImage->sprite->Begin( D3DXSPRITE_ALPHABLEND );
currentInteractiveObject.theImage->sprite->Draw( currentScene.backgroundImage->gTexture, NULL, NULL, ¤tInteractiveObject.pos, 0xFFFFFFFF );
currentInteractiveObject.theImage->sprite->End();
}
}
}