best way to pass value through constructors?

Pages: 12
well, then...I'm doing it wrong. Here's a synopsis:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const int NBR_CELLS = 32;

main() {
   int rv = 55;
   Filter filter(rv);
   ...
}
Filter::Filter(int rv) {
   cell(NBR_CELLS, Cell(rv)) {}
}
Cell:Cell(int rv) {
   cout << "calling constructor." << endl;
   (does something with rv)
}


According to program output, the Cell constructor only gets called once, when it should be called NBR_CELLS times.
You aren't so much wrong as misunderstanding.

The constuctor will be called once

Given the vector constructor :

cellArray(4, Cell(x) )

then the Cell(x) constructor will be called once to create a cell object.

then the Cell copy constructor will be called 4 times to copy construct the vector elements from the Cell object created above.
Oh, OK...of course. I just finished tracking down a few bugs in my constructors, so this wasn't a total loss at all.

Thanks for the help, Gulkan.
Topic archived. No new replies allowed.
Pages: 12