1
//*****************************************************************************
// d3dApp.h by Frank Luna (C) 2011 All Rights Reserved.
//
// Simple Direct3D demo application class.  
// Make sure you link: d3d11.lib d3dx11d.lib D3DCompiler.lib D3DX11EffectsD.lib 
//                     dxerr.lib dxgi.lib dxguid.lib.
// Link d3dx11.lib and D3DX11Effects.lib for release mode builds instead
//   of d3dx11d.lib and D3DX11EffectsD.lib.
//*****************************************************************************

#ifndef D3DAPP_H
#define D3DAPP_H

#include "d3dUtil.h"
#include "GameTimer.h"
#include <string>

class D3DApp
{
    public:
    D3DApp(HINSTANCE hInstance);
    virtual ~D3DApp();

    HINSTANCE AppInst()const;
    HWND      MainWnd()const;
    float     AspectRatio()const;

    int Run();

    // Framework methods.  Derived client class overrides these methods to 
    // implement specific application requirements.

    virtual bool Init();
    virtual void OnResize(); 
    virtual void UpdateScene(float dt)=0;
    virtual void DrawScene()=0; 
    virtual LRESULT MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

    // Convenience overrides for handling mouse input.
    virtual void OnMouseDown(WPARAM btnState, int x, int y){ }
    virtual void OnMouseUp(WPARAM btnState, int x, int y)  { }
    virtual void OnMouseMove(WPARAM btnState, int x, int y){ }

Can someone explain to me why UpdateScene and DrawScene are set = 0? What does that syntax mean?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Eae
  • 4,191
  • 15
  • 55
  • 92
  • 1
    It's called a ["pure virtual function"](http://www.learncpp.com/cpp-tutorial/126-pure-virtual-functions-abstract-base-classes-and-interface-classes/) :) – paulsm4 Jul 30 '13 at 04:53

2 Answers2

3

These methods are intended to be implemented by derived classes using D3DApp as a base. If they are not implemented, compile time error is generated during the instatiation of derived classes. It is basically a design choice to make these method implementations mandatory.

fatihk
  • 7,789
  • 1
  • 26
  • 48
1

This syntax means "pure virtual function". By declaring one or more functions as pure virtual, you're making your class abstract (cannot be instantiated). You're intending to implement these "pure virtual" functions in your child's implementations. You can, however have a body for a pure virtual function in an abstract class, just in case you want to call the parent version from one of the derived objects.

Oleksiy
  • 37,477
  • 22
  • 74
  • 122