我有一个问题,“没有适当的默认构造函数可用”错误,它可能只是一个微小的东西,我失踪。我对C++相当陌生,但我正在慢慢获得它。C++没有合适的默认构造函数可用C2152,但我没有指定任何构造函数?
据我所知,如果不指定任何构造函数,C++将创建一个默认构造函数。但是,即使我没有指定任何构造函数,我也会得到该错误。我已经尝试了Google的解决方案,但其他人要么扩展类错误或有指定构造函数,因此他们得到这个错误。我没有指定任何构造函数,但我仍然得到这个错误。 DirectXGame类在下面。
DirectXGame.h我没有指定任何构造函数,因为他们已经被注释掉
#include "StdAfx.h"
#include "DirectInputHelper.h"
class DirectXGame
{
public:
//DirectXGame();
bool Initialize(HINSTANCE hInstance, HWND windowHandle);
void ShutDown();
bool LoadContent();
void UnloadContent();
void Update(float timeDelta);
void Render();
private:
HINSTANCE progInstance;
HWND winHandle;
D3D_DRIVER_TYPE driverType;
D3D_FEATURE_LEVEL featureLevel;
ID3D11Device* pDev;
ID3D11DeviceContext* pDevContext;
ID3D11RenderTargetView* pBackBufferTarget;
IDXGISwapChain* pSwapChain;
DirectXInput::DirectInputHelper inputHelper;
DirectXInput::KeyboardState* keyboardDevice;
DirectXInput::MouseState* mouseDevice;
bool isShutDown;
};
通知。在我创建类的新实例的主方法中,实际的错误被抛出。
DirectXApp.cpp
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
if(FAILED(InitWindow(hInstance, nCmdShow)))
return 0;
//std::auto_ptr<DirectXGame> DirectXGame(new DirectXGame());
DirectXGame* game = new DirectXGame(); //The compile error is on this line.
bool result = game->Initialize(g_hInst, g_hWnd);
if(!result)
{
game->ShutDown();
return -1;
}
// Main message loop
MSG msg = {0};
while(TRUE)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
break;
}
else
{
game->Update(0.0f);
game->Render();
}
}
game->ShutDown();
//Don't forget to delete the game object, as it is a pointer.
delete game;
return static_cast<int>(msg.wParam);
}
我可能只是缺少你必须用C讲究++中的很多小细节之一。
你是C++的新手,但想要制作DirectX游戏?在堆栈上使用对象有问题吗? – chris
DirectXInput :: DirectInputHelper inputHelper应该是一个指针吗? – Darcara
打赌你没有读完整个错误信息。 –