1

我正在使用 Allen Sherrod 的《Beginning DirectX 11 Game Programming》,Wendy Jones 的书,但我在使用以下代码时遇到了问题:

#include <Windows.h>
#include <memory>
#include "BlankDemo.h"

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, 
                    WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
         LPWSTR cmdLine, int cmdShow)
{
UNREFERENCED_PARAMETER(prevInstance);
UNREFERENCED_PARAMETER(cmdLine);

WNDCLASSEX wndClass = {0};
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = hInstance;
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "DX11BookWindowClass";

if(!RegisterClassEx (&wndClass))
    return -1;

RECT rc = {0, 0, 640, 480};
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);

HWND hwnd = CreateWindowA("DX11BookWindowClass","BlankWin32Window",WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
    rc.bottom - rc.top, NULL,NULL,hInstance,NULL);

if(!hwnd)
    return -1;
ShowWindow(hwnd,cmdShow);

BlankDemo* demo = new BlankDemo();

bool result = demo->Initialize(hInstance, hwnd);

if(result == false)
    return -1;

MSG msg = {0};

while(msg.message != WM_QUIT)
{
    if(PeekMessage(&msg,0,0,0,PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    else
    {
        demo->Update(0.0f);
        demo->Render();
    }
}

demo->Shutdown();

return static_cast<int>(msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, 
                    WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT paintStruct;
HDC hDC;

switch(message)
{
case WM_PAINT:
    hDC = BeginPaint(hwnd, &paintStruct);
    EndPaint(hwnd, &paintStruct);
    break;

case WM_DESTROY:
    PostQuitMessage(0);
    break;

default:
    return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}    

我得到 IntelliSense:抽象类类型“BlankDemo”的对象是不允许的错误。类声明:

#ifndef _BLANK_DEMO_H_
#define _BLANK_DEMO_H_

#include "DemoBase.h"

class BlankDemo : public Dx11DemoBase
{
public:
BlankDemo();
virtual ~BlankDemo();

bool LoadContent();
void UnloadContent();

void Upadate(float dt);
void Render();
};

#endif
4

1 回答 1

0

你拼错了你的一个功能。

void Upadate(float dt);

应该

void Update(float dt);

在早期版本的 C++ 中,此类拼写错误是常见错误。如果你正在编译 C++11,你可以让编译器验证你的意图:

void Update(float dt) override;
于 2013-04-15T17:37:55.730 回答