ConstructorA(游戏game1):基础(game1)意味着什么? [英] constructorA (Game game1) : base (game1) means what?

查看:158
本文介绍了ConstructorA(游戏game1):基础(game1)意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅主题标题.我不完全确定这段代码所包含的内容.当我们可以简单地实例化在游戏的主类中保存ConstructorA的类时,为什么要这样做?

这是我基于此的教程代码.

音频示例 [

see Subject title. I''m not entirely sure what this snippet of code entails. Why would we do this when we could simply instantiate the class that holds ConstructorA in the game''s main class?

Here is the tutorial code I am basing this off of.

Audio Example[^]

In section 1.

推荐答案

这是派生类"constructorA"的构造函数,其参数类型为"Game",该构造函数依次调用,在其初始化程序列表中,具有相同参数类型的基类("base")构造函数将其参数传递给它.

这种机制通常很有用.
That''s the constructor of the derived class ''constructorA'' with parameter of type ''Game'' which in turn calls,in its initializer list, the base class (''base'') constructor with same argument type, passing it its argument.

Such a mechanism is often useful.


它使用传递给派生类构造函数的参数调用基类构造函数.优点是,例如,如果您有多个派生类,并且每个类都想使用相同的构造函数,那么您可以在基类中定义逻辑.
It calls the base classes constructor with the parameter passed to the derived class constructor. The advantage is for example if you have multiple derived classes and you want to use same constructor in each so you can define the logic in the base class.


这意味着一个类的构造函数在进一步初始化之前,使用其基类的构造函数传递类型为Game的变量.

—SA
It means that a constructor of a class uses a constructor of its base class to pass a variable of the type Game before further initialization.

—SA


这篇关于ConstructorA(游戏game1):基础(game1)意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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