【发布时间】:2018-04-29 15:27:56
【问题描述】:
您好,我想使用构造函数将参数传递给类。甚至可能吗? 现在我得到了这个声明:
flight *flight = new flight[random];
好吗?现在我如何调用 *flight 类的构造函数?我声明了这一点,所以我不能调用它说“两次声明”bla bla 的构造函数。 我不能喜欢吗:
flight fl;//assuming I have null constructor too
fl(5);//assuming it takes one argument only.
就没有办法吗?
不能
flight *flight = new flight[random];
同时启动构造函数?
【问题讨论】:
-
您的问题中的信息很少。我们可以肯定地说
_no[i]可能超出范围(如果i是数组中的元素数)。我们需要Minimal, Complete, and Verifiable Example 才能为您提供更多帮助。另外,我建议你看看std::vector或std::array,而不是使用指针或数组。 -
C++ 中的大多数数组问题都可以通过使用
std::vector来解决。