2
我有一個基類,並且在其中放置了一個抽象函數。現在我從它繼承並在派生類中聲明瞭該函數。但Visual Studio仍然不會編譯我的代碼,並堅持派生類是抽象的。我甚至複製並粘貼了基類中的聲明,並刪除了virtual
和=0
,但仍然出現錯誤。我已經明確限定了全局範圍內的所有參數和返回值。有什麼建議麼?無法覆蓋抽象函數CreateFont
#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::Windows::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
);
};
}
}
Windows頭包括渲染頭,相關的摘錄這是貼在下面:
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() {}
};
}
}
編輯:該錯誤是非常明確的。
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'
請張貼代碼示例演示問題 –
也許你有一些預編譯的頭,你點擊構建,而不是重建? –
@Armen:我絕對沒有任何預編譯頭文件。 – Puppy