c++中不需要显示指出struct

 赫  21:48:16
请教个问题

赫  21:49:53
类声明前对私有继承的结构,的struct定义是什么作用?
类声明前对该类私有继承的结构,的struct定义是什么作用?

赫  21:51:21
struct libvlc_instance_t;
struct libvlc_media_player_t;
class CAVPlayer
{
public:
   //......
private:
    libvlc_instance_t       *m_pVLC_Inst;
    libvlc_media_player_t   *m_pVLC_Player;   
};

风雨无阻  21:54:54


应该是这里要用到这两个类型,所以在前面做一下前向声明。应该不是私有继承吧
赫  22:00:19
为什么是struct而不是typedef?
风雨无阻  22:01:54
用typedef什么意思?
赫  22:02:36
额,

呵呵  22:02:41
给数据类型定义一个新名字
赫  22:03:24
不是把libvlc_instance_t,libvlc_media_player_t当作定义了类型使用?

比如typedef libvlc_instance_t libvlc_instance_t;
赫  22:04:26
还是没理解为什么是struct,,,
风雨无阻  22:04:35
struct libvlc_instance_t与libvlc_instance_t是相同的意思,c++中不需要显示指出struct
呵呵  22:04:55
那么libvlc_instance_t就是libvlc_instance_t
C语言里面有这些知识的啊
赫  22:05:29
恩,我再看看书 

c++ primer plus 6th 89页

写道:

如果你熟悉C语言中的结构,则可能已经注意到了,C++允许在声明结构变量时省略关键字struct:

struct inflatable goose; //kerword struct required int C

inflatable vincent; //kerword struct not required in C++

感谢2位师兄,风雨无阻,呵呵参与讨论和指导

提到的代码下载地址:http://download.csdn.net/detail/qq316293804/6398995

原文地址:https://www.cnblogs.com/zero5/p/3512876.html