J
j j
Hi
How can I initialize an array of objects in a constructor initialization
list with a specific values. The following does not work.
#include <iostream>
using namespace std;
struct Wheel {
int radius;
Wheel (int radius) : radius (radius) {}
};
struct Car {
Wheel wheels[2];
Car () : wheels {Wheel(5),Wheel(6)} {} // does not compile
Car (int r1, int r2) : wheels ({r1,r2}) {} // does not compile
};
int main (void)
{
Car c1(1, 2);
Car c2;
return 0;
}
How can I initialize an array of objects in a constructor initialization
list with a specific values. The following does not work.
#include <iostream>
using namespace std;
struct Wheel {
int radius;
Wheel (int radius) : radius (radius) {}
};
struct Car {
Wheel wheels[2];
Car () : wheels {Wheel(5),Wheel(6)} {} // does not compile
Car (int r1, int r2) : wheels ({r1,r2}) {} // does not compile
};
int main (void)
{
Car c1(1, 2);
Car c2;
return 0;
}