Board index » cppbuilder » std::vector assign q
Simon Elliott
CBuilder Developer |
std::vector assign q2005-04-29 08:44:13 PM cppbuilder0 I have some code which works OK with BCB3 but which BCB6 won't compile: #include <vector> struct foo { int i1_; int i2_; }; int main(int argc, char* argv[]) { std::vector<foo>bar; bar.assign(12); // BCB6: ERROR return 0; } [C++ Error] testVector1.cpp(18): E2285 Could not find a match for '_STL::vector<foo,_STL::allocator<foo>>::assign(int)' Can anyone advise why BCB6 won't compile this? If (as I suspect) BCB6 won't compile this because foo has no constructor, why does it work with BCB3? Assuming that I can't change the definition of foo, what's the most elegant way to fix this code? My initial thought was: std::vector<foo>bar; { foo blankFoo; blankFoo.i1_ = 0; blankFoo.i2_ = 0; bar.assign(12, blankFoo); } This seems rather long winded and doesn't lend itself to being made into a template as it needs to know about the innards of foo. Can anyone suggest a better solution? -- Simon Elliott www.ctsn.co.uk |