如何放入 addStaff(const Staff&) 数组中
我不明白如何实现以下代码以允许该函数写入现有数组。
void Project::addStaff(const Staff&)
{
//add employees into staff array
}
将 (const Staff&) 作为参数对我来说是新的,因为它无论如何都不会创建对象。我无法更改它,因为它要按原样使用才能正确实现程序。 Staff 构造函数如下
Staff::Staff (std::string lname, std::string fname)
: theLname(lname), theFname(fname)
{}
有没有办法为 Staff 编写变量,以便我可以访问所需的值并将其放入数组中?任何帮助将不胜感激!
I do not understand how to implement the following code to allow the function to write into the existing array.
void Project::addStaff(const Staff&)
{
//add employees into staff array
}
having (const Staff&) as parameters is new to me as it does not create an object anyways. I can not change it because it is to be used as is to implement the program correctly. the Staff constructor is as follows
Staff::Staff (std::string lname, std::string fname)
: theLname(lname), theFname(fname)
{}
Is there a way to write the variable for staff so I can access the needed values to place into the array? Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
Project
类可能有一个std::vector
数据成员,您可以使用vector.push_back()
方法添加新的数组中的 Staff
实例:Your
Project
class may have astd::vector
data member, and you can usevector.push_back()
method to add newStaff
instances in the array:我将定义
std::vector
表示员工列表作为此Project
类的成员:那么您的
addStaff
方法可能如下所示this:但我肯定会重命名类
Staff
因为它并没有说明太多关于它自己的信息。对于此类来说,Employee
是更好的名称。I would define
std::vector<Staff>
representing list of employees as a member of thisProject
class:Then your
addStaff
method could look like this:But I would definitely rename class
Staff
since it doesn't say much about itself.Employee
would be much better name for this class.