继承构造函数:从C#转换为C++

Sir*_*lot 3 c# c++ inheritance constructor

我来自C#背景,我会写一个类和构造函数,如下所示:

public class Grunt : GameObject
{
    public Grunt()
        : base()
    {
         // do stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在C++中编写构造函数继承?在标题和源中.我知道你没有'base'关键字可以使用,但其他语法是否相同?

Mar*_*k B 6

class Grunt : public GameObject
{
    Grunt()
        : GameObject()  // Since there are no parameters to the base, this line is actually optional.
    {
         // do stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

并强烈考虑在The Definitive C++ Book Guide and List中获得一本优秀的C++书籍


Hen*_*man 5

是的,替换: base(): GameObject().

但是如果没有参数,那么隐含了一个参数,就像在C#中一样