| Bruce Eckel's Thinking in C++, 2nd Ed | Contents | Prev | Next |
for(int i = 0; i < sizeof c / sizeof *c; i++)
struct X {
int i;
float f;
char c;
};
struct Y {
float f;
int i;
Y(int a);//: C06:Multiarg.cpp
// Multiple constructor arguments
// with aggregate initialization
#include <iostream>
using namespace std;
class Z {
int i, j;
public:
Z(int ii, int jj);
void print();
};
Z::Z(int ii, int jj) {
i = ii;
j = jj;
}
void Z::print() {
cout << "i = " << i << ", j = " << j << endl;
}
int main() {
Z zz[] = { Z(1,2), Z(3,4), Z(5,6), Z(7,8) };
for(int i = 0; i < sizeof zz / sizeof *zz; i++)
zz[i].print();