专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > QT开发

一个关于qt c++的有关问题

发布时间:2010-05-30 21:33:08 文章来源:www.iduyao.cn 采编人员:星星草
一个关于qt c++的问题。
今天读QT帮助文档 有这样一段话
To write your own graphics item, you first create a subclass of QGraphicsItem, and then start by implementing its two pure virtual public functions: boundingRect(), which returns an estimate of the area painted by the item, and paint(), which implements the actual painting. 

1、这段话的意思是要想继承QGraphicsItem必须实现这个类里面的两个纯虚函数。boundingRect()、paint()。
2、c++里有春旭函数的类、或者子类没有覆盖纯虚函数的类为抽象类。 抽象类的一个特性是不能声明对象。(大学里c++教材里说的)。
3、按这种说法,QGRaphicsItem就是抽象类了。 那么QGraphicsItem 就不能声明对象。

但是qt里面 可以 QGraphicsItem *item = new QGraphicsItem(this); 声明一个对象啊。

这是怎么回事呢。QT里面是如何实现的呢? 



------解决方案--------------------
但是qt里面 可以 QGraphicsItem *item = new QGraphicsItem(this); 声明一个对象啊。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这样应该会报错的 
error: cannot allocate an object of abstract type 'QGraphicsItem'
------解决方案--------------------
错误:cannot allocate an object of abstract type 'QGraphicsItem'
: because the following virtual functions are pure within 'QGraphicsItem':
: virtual QRectF QGraphicsItem::boundingRect() const
: virtual void QGraphicsItem::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)

如果要是实例化 ,回出现如上的错误,存在纯虚函数;
可以定义其指针对象与引用
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: