奇怪的构造函数 [英] Strange constructor

查看:111
本文介绍了奇怪的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我会在这里很简单,我只是有一段代码在c ++,我不知道我真的了解,需要一些帮助。

Well, I'm gonna be pretty straightforward here, I just have a piece of code in c++ which I'm not sure I really understand and need some help with.

好吧,为了简化让我只是说我有一个类定义如下:(真正的类有点复杂,但这是重要的)

Ok, to simplify lets just say I have a class that is defined like this: (the real class is a little bit more complicated, but this is what matters)

class myClass : public Runnable {
    Semaphore *m_pMySemaphore;
    __Queue<Requests> *m_pQueue;
    Request m_Request;
    VetorSlotBuffer *m_vetorSlotBuffer;
}

到这里没有什么是错误的,myClass只是一个普通的类有3成员实际上是指向其他类的指针和Request类的对象,这些类的实现对我这里不重要。

Up to here nothing is wrong, myClass is just a regular class which has 3 members that actually are pointers to other classes and an object of the class Request, the implementation of those classes not being important for my point here.

然后当这个人实现myClass的构造函数他或她这样做:

Then when this person implemented the constructor for myClass he or she did this:

myClass :: myClass():m_pMySemaphore(0),m_pQueue(0),m_vetorSlotBuffer ){
}

很明显,这三个变量被构造函数看作是指针,对?但是什么样的语法是什么?我是通过这样做的指针设置为null吗?我已经看过一点c ++已经,但从来没有发现这样的东西。

It's pretty evident that those three variables are treated like that by the constructor because they are pointers, am I right? but what kind of syntax is that? am I setting the pointers to null by doing that? I've seen a little bit of c++ already but never found something like that.

其次,在构造函数声明后处理:我已经看过,但从来没有花时间调查。这是一个内在的类还是什么?

And secondly, what's the deal with the ":" after the constructor declaration? that I've seen but never took the time to investigate. Is this like an inner class or something?

非常感谢你。
Nelson R. Perez

Thank you very much in advance. Nelson R. Perez

推荐答案

这是一个初始化列表

这是推荐初始化您的成员的方式

这篇关于奇怪的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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