Visual Studio 2015“无法实例化抽象类”编译失败构建 openFrameworks 0.9.0

Posted

技术标签:

【中文标题】Visual Studio 2015“无法实例化抽象类”编译失败构建 openFrameworks 0.9.0【英文标题】:Visual Studio 2015 "cannot instantiate abstract class" compile failures building openFrameworks 0.9.0 【发布时间】:2015-08-16 22:21:33 【问题描述】:

我正在尝试使用 Visual Studio 2015 构建 openFrameworks 0.9.0,但出现“无法实例化抽象类”编译失败。但是,我觉得这更有可能是 VS2015 语法问题而不是 openFrameworks 问题。此代码使用 Visual Studio 2012 和 openFrameworks 0.8.4 构建。有谁知道实现类的语法应该如何满足 VS2015 的要求?

VS2015 编译的错误是:

ofx*.cpp(46): error C2259: 'ofx*': cannot instantiate abstract class 1> ......\addons\ofx*I\libs\src\ofx*.cpp(46): note: due to following members: 1> ......\addons\ofx*I\libs\src\ofx*.cpp(46): note: 'void ofBaseDraws::draw(float,float,float,float) const': is abstract 1> ...of_v0.9.0_vs_release\libs\openFrameworks\types\ofBaseTypes.h(75): note: see declaration of 'ofBaseDraws::draw'

1> ......\addons\ofx*I\libs\src\ofx*.cpp(46): note: 'void ofBaseDraws::draw(float,float) const': is abstract 1> ...of_v0.9.0_vs_release\libs\openFrameworks\types\ofBaseTypes.h(67): note: see declaration of 'ofBaseDraws::draw'

1> ......\addons\ofx*I\libs\src\ofx*.cpp(46): note: 'float ofBaseDraws::getHeight(void) const': is abstract 1> ...of_v0.9.0_vs_release\libs\openFrameworks\types\ofBaseTypes.h(104): note: see declaration of 'ofBaseDraws::getHeight'

1> ......\addons\ofx*I\libs\src\ofx*.cpp(46): note: 'float ofBaseDraws::getWidth(void) const': is abstract 1> ...of_v0.9.0_vs_release\libs\openFrameworks\types\ofBaseTypes.h(108): note: see declaration of 'ofBaseDraws::getWidth'

继承类的代码: of_v0.9.0_vs_release\libs\openFrameworks\types\ofBaseTypes.h

具有抽象对象:ofBaseDraws...具有以下声明:

/// \brief Draw at a position at the native size.
///
/// Native size is determined by getWidth() and getHeight().
///
/// \param x Draw position on the x axis.
/// \param y Draw position on the y axis.
virtual void draw(float x, float y) const=0;

/// \brief Draw at a position with the specified size.
///
/// \param x Draw position on the x axis.
/// \param y Draw position on the y axis.
/// \param w Draw width.
/// \param h Draw height.
virtual void draw(float x, float y, float w, float h) const=0;

如下:

/// \brief Draw at a position at the native size.
///
/// Native size is determined by getWidth() and getHeight().
///
/// \param x Draw position on the x axis.
/// \param y Draw position on the y axis.
virtual void draw(float x, float y) const=0;

/// \brief Draw at a position with the specified size.
///
/// \param x Draw position on the x axis.
/// \param y Draw position on the y axis.
/// \param w Draw width.
/// \param h Draw height.
virtual void draw(float x, float y, float w, float h) const=0;
...............................................

/// \brief Get the height.
/// \returns the height.
virtual float getHeight() const = 0;

/// \brief Get the width.
/// \returns the width.
virtual float getWidth() const = 0;

用VS2012构建的openFrameworks 0.8.4代码略有不同:

virtual void draw(float x, float y)=0;
virtual void draw(float x, float y, float w, float h)=0;
...............................................
virtual float getHeight()=0;
virtual float getWidth()=0;

【问题讨论】:

在以下位置找到约定:of_v0.9.0_vs_release\libs\openFrameworks\gl\ofTexture.h: 【参考方案1】:

对不起,但必须承认自己找到了答案(尴尬):

在以下位置找到约定:of_v0.9.0_vs_release\libs\openFrameworks\gl\ofTexture.h:

using ofBaseDraws::draw;

void draw(float x, float y) const;
void draw(float x, float y, float w, float h) const;
float getHeight() const;
float getWidth() const;

//*** and in ofTexture.cpp:

void draw(float x, float y) 
.....

void draw(float x, float y, float w, float h) 
....

float getHeight() 
return height;

float getWidth() 
return width;

【讨论】:

以上是关于Visual Studio 2015“无法实例化抽象类”编译失败构建 openFrameworks 0.9.0的主要内容,如果未能解决你的问题,请参考以下文章

visual studio 2015 和.net 啥区别

visual studio 2015怎么破解

visual studio 2015 怎么更新

在 Visual Studio 2015 中打开 Visual Studio 2017 项目

studio vs2015啥软件

visual studio 2015怎么用