【发布时间】:2020-09-15 13:20:57
【问题描述】:
在struct creat array中创建一个指针,使用for循环初始化-1,10次,使用struct中的方法打印-1,10次。
struct hasha {
int* arr;
int l;
hasha(int no) {
arr[no];
l = no;
for (int i = 0; i < l; i++) {
arr[i] = -1;
}
}
void print() {
for (int i = 0; i < l; i++) {
cout << arr[i] << " ";
}
}
};
int main() {
hasha a(10);
a.print();
}
【问题讨论】:
-
谁给了你这个任务也应该为你提供了所需的基础知识,也可以在这里查看:stackoverflow.com/questions/388242/…
-
使用
std::vector,否则您必须手动进行分配/解除分配。 -
std::vector<int> a(10, -1); for (auto e : a) {std::cout << e << " ";}. -
“创造”是什么意思?
-
arr[no]不创建数组。回顾你最近学到的东西。
标签: c++ pointers methods struct constructor