开发者

Can't override abstract function CreateFont

开发者 https://www.devze.com 2023-03-15 09:26 出处:网络
I\'ve got a base class, and I put an abstract function in it. Now I\'ve inherited from it and declared that function in my derived class. But Visual Studio still won\'t compile my code and insists tha

I've got a base class, and I put an abstract function in it. Now I've inherited from it and declared that function in my derived class. But Visual Studio still won't compile my code and insists that the derived class is abstract. I even copied and pasted the declaration from the base class and just removed the virtual and =0 and still got the error. I've explicitly qualified all the arguments and return values from global scope. Any suggestions?

#include "OS/Windows/Windows.h"

#ifdef _DEBUG
#define D3D_DEBUG_INFO
#define D3DCALL(a) Wide::Render::CheckResult(a, #a)
#else
#define D3DCALL(a) a
#endif
#define D3DXFX_LARGEADDRESS_HANDLE

extern "C" {
    Wide::Render::Render* CreateRender(Wide::OSystem::Windows::WindowsOS* ptr);
}

namespace Wide {
    namespace Render {
        class D3D9Render : public Wide::Render::Render {
            friend Render* ::CreateRender(Wide::OSystem::Wi开发者_运维问答ndows::WindowsOS*);
            D3D9Render(Wide::OSystem::Windows::WindowsOS* os);

            Wide::Colour ScreenBackground;

        public:
            Wide::Colour GetScreenBackground();
            Render* SetScreenBackground(Wide::Colour);
            void RenderFrame();

            int GetFramesPerSecond();
            std::shared_ptr<Wide::Render::Font> GetDefaultFont();
            std::shared_ptr<Wide::Render::Font> CreateFont(
                string name, 
                int weight,
                int width, 
                int height,
                bool italic
            );
        };
    }
}

The Windows header includes the Render header, the pertinent excerpt of which is posted below:

namespace Wide {
    namespace Render {
        struct Font;
        struct Label {
            virtual ::Wide::string Text() = 0;
            virtual Label* Text(::Wide::string) = 0; 

            virtual std::shared_ptr<::Wide::Render::Font> Font() = 0;
            virtual Label* Font(std::shared_ptr<::Wide::Render::Font>) = 0;

            virtual Label* Position(::Wide::Rectangle) = 0;
            virtual ::Wide::Rectangle Position() = 0;

            virtual ::Wide::Colour Colour() = 0;
            virtual Label* Colour(::Wide::Colour) = 0;

            virtual ~Label() {}
        };
        struct Font {
            virtual ::Wide::string Name() const = 0;
            virtual bool Italic() const = 0;
            virtual int Weight() const = 0;
            virtual int Width() const = 0;
            virtual int Height() const = 0;
            virtual std::unique_ptr<::Wide::Render::Label> CreateLabel() = 0;

            virtual ~Font() {}
        };
        struct Texture;
        struct Sprite {        
            virtual std::shared_ptr<::Wide::Render::Texture> Texture() = 0;
            virtual Sprite* Texture(std::shared_ptr<::Wide::Render::Texture>) = 0;

            virtual Sprite* Position(::Wide::Rectangle) = 0;
            virtual ::Wide::Rectangle Position() = 0;

            virtual ::Wide::Colour Colour() = 0;
            virtual Sprite* Colour(::Wide::Colour) = 0;

            virtual float Depth() = 0;
            virtual Sprite* Depth(float) = 0;

            virtual ~Sprite() {}
        };
        struct Texture {
            virtual ::Wide::Point Size() = 0;
            virtual ::Wide::string Filepath() = 0;

            virtual std::unique_ptr<Sprite> CreateSprite() = 0;
            virtual ~Texture() {}
        };
        struct Render {
            virtual ::Wide::Colour GetScreenBackground() = 0;
            virtual Render* SetScreenBackground(::Wide::Colour) = 0;
            virtual void RenderFrame() = 0;
            virtual int GetFramesPerSecond() = 0;

            virtual std::shared_ptr<Wide::Render::Font> GetDefaultFont() = 0;
            virtual std::shared_ptr<Wide::Render::Font> CreateFont(
                string name, 
                int weight,
                int width, 
                int height,
                bool italic
            ) = 0;

            virtual ~Render() {}
        };
    }
}

Edit: The error is extremely explicit.

d:\backups\code\projects\ngin4\d3d9render\d3d9render.cpp(9): error C2259: 'Wide::Render::D3D9Render' : cannot instantiate abstract class
          due to following members:
          'std::tr1::shared_ptr<_Ty> Wide::Render::Render::CreateFont(Wide::string,int,int,int,bool)' : is abstract
          with
          [
              _Ty=Wide::Render::Font
          ]
          d:\backups\code\projects\ngin4\ngin4\render.h(107) : see declaration of 'Wide::Render::Render::CreateFont'


The windows.h defines CreateFont as CreateFontW (and many other identifiers in a similar way), resulting in many surprising compilation errors with some inclusion orders:

#define CreateFont CreateFontW

A common workaround (assuming you do not need to call this GDI function) is to undefine the symbol after including windows.h, or to avoid using names of such Win32 APIs completely.

#undef CreateFont
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号