【发布时间】:2017-05-02 04:16:05
【问题描述】:
好的,我搜索了问题,但找不到答案,或者没有使用合适的术语。
if(choice == 2){
string tempName, tempAddress; int tempNic,tempContact;
cout << "\n\t\t*\tWelcome to Our Sponsor Registeration Section\t*\n\n";
cout << "Please enter your name : "; cin>>tempName;
cout << "Please enter your National Identity Card Number : "; cin>>tempNic;
cout << "Please enter your Contact Number : "; cin>>tempContact;
cout << "Please enter your Address : "; cin>>tempAddress;
// prototype Sponsor(string n, string add, int nic_n, int phone) constructor
Sponsor (Constructor goes here) // how to make many objects now?
}
代码贴在这里https://codeshare.io/aVxl42
检查第 69 行,我将在其中使用构造函数添加值,这样我可以添加 1 个对象,但是如果正在使用程序的人想要添加更多对象,我应该怎么做呢?
我知道我需要封装 61 到 70 之间的东西。 请帮我解决这个问题。
【问题讨论】:
-
请在问题正文中直接包含相关代码。如果有我们应该阅读的特殊行,则用例如标记它们。厘米。想想如果链接消失会发生什么,那将使这个问题变得毫无价值。请read about how to ask good questions,并学习如何创建Minimal, Complete, and Verifiable Example。
-
我不太确定你想做什么,但特定对象类型的列表 (cplusplus.com/reference/list/list) 或向量 (cplusplus.com/reference/vector/vector/vector) 可能会有所帮助。
-
将用户输入请求放入循环中,并将创建的 Sponsor 添加到向量中。
-
你可以创建一个对象数组,然后循环填充它
标签: c++ oop object constructor