【发布时间】:2012-06-17 02:34:41
【问题描述】:
感谢 Microsoft 的 Intellisense 和 Atomineer 的 Atomineer Utils...所有这些参数都是必需且不可变的。
有没有更好的方法来做到这一点?
/**************************************************************************************************
* <summary>Initializes a new instance of the ADTBattleCharacter class.</summary>
* <param name="name"> The name of the character.</param>
* <param name="max_HP"> The maximum hit points.</param>
* <param name="max_MP"> The maximum magic power.</param>
* <param name="strength"> The strength.</param>
* <param name="agility"> The agility.</param>
* <param name="attack_power"> The attack power.</param>
* <param name="defense_power">The defense power.</param>
* <param name="gold"> The gold carried by the character.</param>
* <param name="experience"> The experience the character is worth.</param>
* <param name="stop_resist"> The character's resistance to stopspell.</param>
* <param name="sleep_resist"> The character's resistance to sleep.</param>
* <param name="hurt_resist"> The character's resistance to hurt/hurtmore.</param>
* <param name="spell_list"> Available spells.</param>
**************************************************************************************************/
ADTBattleCharacter(std::string name, unsigned char max_HP, unsigned char max_MP,
unsigned char strength, unsigned char agility,
unsigned char attack_power, unsigned char defense_power,
unsigned short gold, unsigned short experience,
double stop_resist, double sleep_resist, double hurt_resist,
std::bitset<SPELL_MAX> spell_list);
【问题讨论】:
-
您不能将它们全部打包到某个容器对象中并传递它吗?
-
将 em 放入一个结构体中,提供默认值或基于其他值,更改您需要的值,然后将结构体传入?
-
@chris,这只是将问题推给结构的构造函数。并没有真正改变任何东西。
-
@Mark:为什么
struct需要构造函数?这是一个结构;类型的集合。它不是智能对象;这只是一袋东西。 -
@NicolBolas,关键是任何适合填充结构的解决方案也适合首先创建对象。使用结构是不必要的中间步骤。
标签: c++ parameters constructor