Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication5.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <vector>;
- using namespace std;
- class Base{
- public:
- int *f ;
- Base(){
- f = new int;
- *f=99;
- }
- virtual ~Base(){
- delete f;
- }
- virtual Base* copy(){
- return new Base(*this);
- }
- Base(const Base & obj): f(new int){
- *f=*(obj.f);
- }
- };
- class Second:public Base{
- public:
- Second(){
- *f=11;
- }
- ~Second(){
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- Base* a= new Base;
- Base* b= new Second ;
- vector <Base*> v;
- v.push_back( a );
- v.push_back ( b );
- vector <Base*> v2;
- for (int i=0; i < v.size(); i++){
- Base* b= v[i]->copy();
- v2.push_back(b);
- }
- for (int i=0; i<v.size(); i++){
- delete v[i];
- }
- for (int i=0; i<v2.size(); i++){
- delete v2[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement