Hello,
I have a sample code which is a header file and I am trying to write a CPP program which uses this file. But I am getting errors while running the code.
Here is the header file:
#ifndef FineInterfacePtr_h
#define FineInterfacePtr_h
template<class T>
class CSafePtr {
public:
CSafePtr( T* _iface = 0 ) { attach( _iface ); }
CSafePtr( const CSafePtr& other ) { attach( other.iface ); }
~CSafePtr() { release(); }
bool IsNull() const { return iface == 0; }
T** GetBuffer();
void** GetQIBuffer();
T& operator *() const { return *iface; }
T* operator ->() const { return iface; }
operator T*() const { return iface; }
CSafePtr& operator = ( const CSafePtr& other );
CSafePtr& operator = ( T* _iface );
private:
void attach( T* _iface );
void release();
T* iface;
};
template<class T>
inline T** CSafePtr<T>::GetBuffer()
{
release();
return &iface;
}
template<class T>
inline void** CSafePtr<T>::GetQIBuffer()
{
release();
return reinterpret_cast<void**>(&iface);
}
template<class T>
inline CSafePtr<T>& CSafePtr<T>::operator = ( const CSafePtr<T>& other )
{
if( other.iface != iface ) {
release();
attach( other.iface );
}
return *this;
}
template<class T>
inline CSafePtr<T>& CSafePtr<T>::operator = ( T* _iface )
{
if( _iface != iface ) {
release();
attach( _iface );
}
return *this;
}
template<class T>
inline void CSafePtr<T>::attach( T* _iface )
{
if( _iface != 0 ) {
_iface->AddRef();
}
iface = _iface;
}
template<class T>
inline void CSafePtr<T>::release()
{
if( iface != 0 ) {
iface->Release();
}
iface = 0;
}
#endif // FineInterfacePtr_h
In the .cpp file I have declared a object to the class as:
CSafePtr<int> myobject(int* t);
and when I try to call the function GetBuffer() I get the following error:
Structure required on the left side of . or .* in the function main().
Can anyone please let me know how to call the function GetBuffer()and why this error is coming.
Any help would be really appriciated.
Thank you,
Swathi