Basically I want to create an instance of a class and make an array with duplicate entries of the previous instance created.
I don't really think looping through the entire lot and assigning a duplicate is the best method, is there a way I can do this via a constructor or other form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//Non-working example of what I want to do
class Test {
public:
int randomDataMember;
bool anotherDataMember;
};
int main {
Test test;
test.randomDataMember = 3;
test.anotherDataMember = true;
vector<Test, test> bunch(10); //Of type Test, duplicate instance test
cout << bunch[5].randomDataMember;
return 0;
}
Oh, oh I'm very sorry, but this is Abuse. No no, you'll want 12A, that's just next door.
I have no idea why I put in that Monty Python quote, but it's irrelevant. That constructor you used is a copy constructor provided you have another vector. You'll want the second constructor from the top.
Hey, maybe it wasn't so irrelevant. I didn't specify which constructor, the Python member didn't specify which room 12. ;)
Nope. One's a member of vector, the other IS a vector. :P
I get what you're saying though. You can safely substitute int for size_type and T for Test (provided that your vector is of "type <Test>, which it is).