一个类有虚拟数据成员吗? [英] can a class have virtual data members?

查看:83
本文介绍了一个类有虚拟数据成员吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Base{  
    public:  
        void counter();   
    ....   
}

class Dervied: public Base{  
    public:  
        ....  
}

void main()  
{  
     Base *ptr=new Derived;  
     ptr->counter();  
}

要标识基类指针指向派生类,成员函数,我们使用虚拟。

To identify that the base class pointer is pointing to derived class and using a derived member function, we make use of "virtual".

同样,我们可以使派生数据成员虚拟吗? (数据成员是公开的)

Similarly, can we make derived data members "virtual"? (the data member is public)

推荐答案

virtual > Function specifier ...

virtual is a Function specifier...

从标准文档中,

7.1.2 Function specifiers
Function-specifiers can be used only in function declarations.
function-specifier:
inline
virtual
explicit



<

So there is nothing called Virtual data member.

希望它有助于...

这篇关于一个类有虚拟数据成员吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆