[COM] [예제] COM Aggregation 에서의 casting
CS/COM 2009. 4. 24. 07:00COM공부중 Aggregation 공부하던중 왠지 casting 부분에서 급 혼란. -_-;
Casting을 하게 되면, Casting된 Object를 Base class부터 생각하고, 이후 그 Object의 Derived class를 생각하자!!! -_-;;;
class IUnknown { public: virtual void QueryInterface() = 0; virtual void AddRef() = 0; virtual void Release() = 0; }; class IDummy : public IUnknown { public: virtual void Fx() = 0; }; class INondelegatingUnknown { public: virtual void NondelegatingQueryInterface() = 0; virtual void NondelegatingAddRef() = 0; virtual void NondelegatingRelease() = 0; }; class C : public IDummy, public INondelegatingUnknown { public: virtual void QueryInterface() { std::cout << "QueryInterface" << std::endl; } virtual void AddRef() { std::cout << "AddRef" << std::endl; } virtual void Release() { std::cout << "Release" << std::endl; } virtual void NondelegatingQueryInterface() { std::cout << "NondelegatingQueryInterface" << std::endl; } virtual void NondelegatingAddRef() { std::cout << "NondelegatingAddRef" << std::endl; } virtual void NondelegatingRelease() { std::cout << "NondelegatingRelease" << std::endl; } virtual void Fx() { std::cout << "Fx()" << std::endl; } C(); public: IUnknown* m_pI; void Go(); }; C::C() { m_pI = reinterpret_cast<IUnknown*> ( static_cast<INondelegatingUnknown*>(this) ); } void C::Go() { m_pI->QueryInterface(); } int _tmain(void) { C c; c.Go(); return 0; }
Inside COM Aggregation 예제