P
Peng Yu
Hi,
I'm wondering if there is a way to initialized a member array just as
the initialization of a member variable? Or I have to initialized the
array inside the function body of the constructor?
Thanks,
Peng
#include <iostream>
struct A {
A() : array({0, 1, 2, 3}), variable(100) { }
int array[4];
int variable;
};
int main() {
A a;
std::cout << a.array[0] << std::endl;
std::cout << a.variable << std::endl;
}
I'm wondering if there is a way to initialized a member array just as
the initialization of a member variable? Or I have to initialized the
array inside the function body of the constructor?
Thanks,
Peng
#include <iostream>
struct A {
A() : array({0, 1, 2, 3}), variable(100) { }
int array[4];
int variable;
};
int main() {
A a;
std::cout << a.array[0] << std::endl;
std::cout << a.variable << std::endl;
}