constructor array

Started by
1 comment, last by visitor 14 years, 5 months ago
So I currently have this as an object declaration in a C++ file. obj bullet(0.f,0.f,0.f,0.f); I was wondering if I could do this obj bullet[3](0.f,0.f,0.f,0.f); and save myself the trouble of putting down three constructors.
Advertisement
Unfortunately that's not possible (otherwise you wouldn't have asked in the first place).

But, if you used an std::vector, instead of a plain old array, you could to it like this:

std::vector<obj> bullet(3, obj(0.f,0.f,0.f,0.f));


Tadaa!
Also obj could have a default constructor, that initializes all fields to 0.

This topic is closed to new replies.

Advertisement