전략 패턴1 [C++ Design Pattern] Strategy Pattern strategy pattern(전략 패턴) template struct IAllocator { virtual T* allocate(int size) = 0; virtual void deallocate(T* p, int size) = 0; virtual ~IAllocator() {} }; template class vector { T* buff; IAllocator* ax; public: void set_allocator(IAllocator* p) { ax = p; } void resize(int n) { buff = ax->allocate(n); ax->deallocate(buff, n); } }; template class newAllocator : public IAllocator { public: T.. 2023. 11. 29. 이전 1 다음