Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Osoba
- {
- string imie, nazwisko;
- int wiek;
- };
- template <typename T>
- class Box
- {
- private:
- T*wsk;
- public:
- Box():wsk(new T){}
- Box(T *a):wsk(new T(*a)){}
- Box(const Box&a):wsk(new T(*a.wsk)){}
- Box&operator=(const Box&a)
- {
- if(this!=&a)
- {
- delete wsk;
- wsk=new T(*a.wsk);
- }
- return *this;
- }
- T*operator->()
- {
- return wsk;
- }
- T&operator*()
- {
- return *wsk;
- }
- ~Box()
- {
- delete wsk;
- wsk=0;
- }
- };
- int main()
- {
- Box<int>w;
- Box<double>w2;
- Box<Osoba>w3;
- cout<<*w<<" "<<w3->wiek;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement