2002 TIF

2002 TIF



/Wskazówka 59.

template <class T> class ObjectSmartPointer : public BaseSmartPointer <T>

{

private:

// Prywatne, aby uniemożliwić innym użycie konstruktora kopiowania. ObjectSmartPointer(ObjectSmartPointer<T>&osp)

{

}

public:

ObjectSmartPointer(T* pt=NULL) : BaseSmartPointer<T>(pt)

{

}

T* operator=(T *pt)

{

return BaseSmartPointer<T>::operator=(pt);

}

T *operator->() const

{

return m_pt;

}

};

class foo

{

public: int i; float f;

};

Smartptr.cpp

#include "smartptr.h"

#include "iostream.h" void TestSmartPointer(void)

{

BaseSmartPointer<int> pi; ObjectSmartPointer<foo> po;

po = new foo; po->i = 10; po->f = 10.5;

cout « (*po).i « "" « po->f « "\n"; pi = new int; pi = new int;


Wyszukiwarka

Podobne podstrony:
Smartptr.h #include <stdio.h> //Wskazówka 58. //Wskazówka 60. template <dass T> class
Listing 2.1: Implementacja struktury Graph<V,E> 01    template <class V, cla
Sortowanie kontenera - procedura testowa template<class T> void con_sort(unsigned int size){ s
133 TIF class C3 : public C1{ public: void Metoda3();}; class C4 : public C3, public C2{}; void
Python - klasy □ Dziedziczenie class A(object): def methodl(self): print "Class A : methodl&quo
133 TIF class C3 : public C1{ public: void Metoda3();}; class C4 : public C3, public C2{}; void
Listing 5: ObjectFactory 1    public class ObjectFactory ( 2    privat
f30 1 LŹ template3 THE C0MPARE1 OBJECT Lowest: 15 Highest: 25 Equal: 0 THE COMPARE2 OBJECT
18 p05 #include <stdio.h> #include <conio.c> class HojaKlasa { public: int
18 p06 #include <stdio.h> #include <conio.c> class HojaKlasa { public: int
19 p02 #include <stdio.h> class próba { public: int    aa; int
19 p03 #include <stdio.h> class próba { public: int    aa; int

więcej podobnych podstron