Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- template <class M = std::string, class E = int>
- E log(M msg, E error = 0)
- {
- std::cout << msg;
- return error;
- }
- struct Cell
- {
- int index;
- };
- std::vector<Cell*> vecInt;
- void showVec()
- {
- log("\n Vec = ");
- for (auto & it: vecInt)
- {
- std::cout << "[ " << it->index << " ]";
- }
- }
- void resizeVec(unsigned newSize)
- {
- if (newSize < vecInt.size())
- {
- for (int i=0; i < newSize - 1; ++i)
- {
- delete vecInt.back();
- vecInt.pop_back();
- }
- vecInt.resize(newSize);
- }
- else if (newSize > vecInt.size())
- {
- vecInt.resize(newSize, new Cell{0});
- }
- else if (newSize == vecInt.size())
- {
- log ("\n Nothing to resize !\n");
- }
- }
- int main()
- {
- for (int i=0; i<5; ++i)
- {
- vecInt.push_back(new Cell{i});
- }
- showVec();
- resizeVec(7);
- showVec();
- resizeVec(4);
- showVec();
- resizeVec(4);
- showVec();
- return log("\n--- End of Main ---\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement