Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int count;
- struct foo{
- foo(){id = 0;}
- ~foo(){ //Catch the message here...
- count++;
- std::cout << "The variable id (" << id << ") is destroyed. (" << count << ")\n";
- }
- int id;
- };
- int main()
- {
- tVector<foo> vec;
- foo obj;
- int i;
- for(i = 0;i < 10;i++){
- vec.push_back(obj); //Avoid temporary constructors & destructors
- vec.back().id = i;
- }
- vec.reserve(1000); // Causes an automatic reallocation
- std::cout << "foo size : " << vec.size() << " - capacity : " << vec.capacity() << std::endl;
- vec.shrink_to_fit(); // Same here
- std::cout << "foo size : " << vec.size() << " - capacity : " << vec.capacity() << std::endl;
- //cout << "Try deleting some elements...\n";
- //vec.erase(vec.begin() + 3, vec.begin() + 8);
- printf("my vector contains : \n");
- for(i = 0;i < vec.size();i++)
- cout << "vec[" << i << "] = " << vec[i].id << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement