I have done some Java programming before where you can pass an array through the constructor of a class to initialize it.
public class Student {
int age;
String name;
int[] classIds;
public Student(int age, String name, int[] classIds) {
this.age = age;
this.name = name;
this.classIds = classIds;
}
}
int[] classIds = {1, 2, 3};
Student student = new Student(5, "Claudia", classIds);
But I can't figure out how to pass an array through the constructor in C++
class Student
{
public:
int age;
string name;
int classIds[];
Student()
{
}
Student(int age, string name, int classIds[])
{
this->age = age;
this->name = name;
this->classIds = classIds;
}
};
How would I do this? It's giving the lint error incomplete type is not allowed in VSCode
std::arraycontainer from the STL - that will be copyable. Orstd::vector, if you have variable-sized arrays.