The following prints "1\n 1\n 1" as expected. Can I construct "ar" in a way that it will print "2\n 2\n 2" without giving it an explicit initializer list (... ar = {A(2), A(2), A(2)})?
#include <iostream>
#include <array>
class A {
public:
A(int i=1) : m_i(i) {};
int m_i;
};
int main() {
std::array<A, 3> ar;
for(auto& v : ar) {
std::cout << v.m_i << std::endl;
}
}
Aucun commentaire:
Enregistrer un commentaire