M
mosfet
Hi,
I am trying to rewrite an existing class used to manage personal
data(Outlook) with Smart Pointers (RefPtr a reference counting ptr):
namespace System{
namespace WindowsMobile{
namespace PocketOutlook{
....
In .h
#include "RefPtr.h"
class OutlookSession : public Object
{
public:
friend class Folder;
friend class ContactCollection;
friend class TaskCollection;
OutlookSession();
virtual ~OutlookSession();
bool get_IsLoggedIn() {return m_bLoggedIn; }
System::RefPtr<ContactFolder> get_Contacts();
protected:
bool m_bLoggedIn;
IPOutlookAppPtr m_pPOOMApp;
RefPtr<ContactFolder> m_rpContactFolder;
};
} // PocketOutlook
} // WindowsMobile
} // System
In .cpp
namespace System{
namespace WindowsMobile{
namespace PocketOutlook{
RefPtr<ContactFolder> OutlookSession::get_Contacts()
{
if ( (m_bLoggedIn == false) )
return NULL;
if (m_rpContactFolder.isNull() == true)
m_rpContactFolder = new ContactFolder();
return m_rpContactFolder;
}
}
}
}
But when I compile I get the following error :
System::WindowsMobile:ocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder>(void)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@XZ)
referenced in function "public: __cdecl
System::WindowsMobile:ocketOutlook::OutlookSession::OutlookSession(void)"
(??0OutlookSession@PocketOutlook@WindowsMobile@System@@QAA@XZ)
1>System.WindowsMobile.PocketOutlook.obj : error LNK2019: unresolved
external symbol "public: __cdecl System::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder>(class
System::WindowsMobile:ocketOutlook::ContactFolder *)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@PAVContactFolder@PocketOutlook@WindowsMobile@1@@Z)
referenced in function "public: class System::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder> __cdecl
System::WindowsMobile:ocketOutlook::OutlookSession::get_Contacts(void)"
(?get_Contacts@OutlookSession@PocketOutlook@WindowsMobile@System@@QAA?AV?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@4@XZ)
1>Windows Mobile 6 Standard SDK (ARMV4I)\Debug\TestPoom.exe : fatal
error LNK1120: 2 unresolved externals
I don't understand ths missing reference since I am including RefPtr.h
(see below) :
File RefPtr.h
-----------------
#ifndef RefPtr_h
#define RefPtr_h
namespace System{
template<typename T>
class RefPtr
{
public:
~RefPtr();
RefPtr();
RefPtr(const RefPtr<T>& rhs);
RefPtr(T* ptr);
RefPtr<T>& operator=(const RefPtr<T>& rhs);
RefPtr<T>& operator=(T* ptr);
bool operator<(const RefPtr<T>& rhs) const;
bool operator==(const RefPtr<T>& rhs) const;
bool operator==(const T* rhs) const;
bool operator!=(const RefPtr<T>& rhs) const;
bool operator!=(const T* rhs) const;
bool isNull() const;
operator bool() const;
T* operator->() const;
T& operator*() const;
T* get() const;
void Release();
private:
T* m_ptr;
};
} // namespace System
#include "RefPtr.inl"
#endif
File RefPtr.inl
-----------------
namespace System{
template<typename T>
inline
RefPtr<T>::RefPtr(const RefPtr& rhs) : m_ptr(rhs.m_ptr)
{
if(m_ptr)
m_ptr->AddRef();
}
template<typename T>
inline
RefPtr<T>& RefPtr<T>:perator=(const RefPtr<T>& rhs)
{
T* const pNew = rhs.get();
if(m_ptr != pNew)
{
T* const pOld = m_ptr;
if(pNew)
pNew->AddRef();
m_ptr = pNew;
if(pOld)
pOld->Release();
}
return *this;
}
template<typename T>
inline
RefPtr<T>& RefPtr<T>:perator=(T* ptr)
{
if(m_ptr != ptr)
{
if(ptr)
ptr->AddRef();
T* const pOld = m_ptr;
m_ptr = ptr;
if(pOld)
pOld->Release();
}
return *this;
}
template<typename T>
inline
bool RefPtr<T>:perator<(const RefPtr& rhs) const
{
return (m_ptr < rhs.m_ptr);
}
template<typename T>
inline
bool RefPtr<T>:perator==(const RefPtr& rhs) const
{
return (m_ptr == rhs.m_ptr);
}
template<typename T>
inline
bool RefPtr<T>:perator==(const T* rhs) const
{
return (m_ptr == rhs);
}
template<typename T>
inline
bool RefPtr<T>:perator!=(const RefPtr& rhs) const
{
return !(*this == rhs);
}
template<typename T>
inline
bool RefPtr<T>:perator!=(const T* rhs) const
{
return (m_ptr != rhs);
}
template<typename T>
inline
RefPtr<T>:perator bool() const
{
return (m_ptr!=0);
}
template<typename T>
inline
bool RefPtr<T>::isNull() const
{
return (m_ptr == 0);
}
template<typename T>
inline
T* RefPtr<T>::get() const
{
return m_ptr;
}
template<typename T>
inline
T* RefPtr<T>:perator->() const
{
ASSERT(m_ptr!=0);
return m_ptr;
}
template<typename T>
inline
T& RefPtr<T>:perator*() const
{
ASSERT(m_ptr!=0);
return *m_ptr;
}
template<typename T>
inline
RefPtr<T>::~RefPtr()
{
Release();
}
template<typename T>
inline
void RefPtr<T>::Release()
{
if(m_ptr)
{
m_ptr->Release();
m_ptr = 0;
}
}
} //namespace System
I am trying to rewrite an existing class used to manage personal
data(Outlook) with Smart Pointers (RefPtr a reference counting ptr):
namespace System{
namespace WindowsMobile{
namespace PocketOutlook{
....
In .h
#include "RefPtr.h"
class OutlookSession : public Object
{
public:
friend class Folder;
friend class ContactCollection;
friend class TaskCollection;
OutlookSession();
virtual ~OutlookSession();
bool get_IsLoggedIn() {return m_bLoggedIn; }
System::RefPtr<ContactFolder> get_Contacts();
protected:
bool m_bLoggedIn;
IPOutlookAppPtr m_pPOOMApp;
RefPtr<ContactFolder> m_rpContactFolder;
};
} // PocketOutlook
} // WindowsMobile
} // System
In .cpp
namespace System{
namespace WindowsMobile{
namespace PocketOutlook{
RefPtr<ContactFolder> OutlookSession::get_Contacts()
{
if ( (m_bLoggedIn == false) )
return NULL;
if (m_rpContactFolder.isNull() == true)
m_rpContactFolder = new ContactFolder();
return m_rpContactFolder;
}
}
}
}
But when I compile I get the following error :
external symbol "public: __cdecl System::RefPtr<class>System.WindowsMobile.PocketOutlook.obj : error LNK2019: unresolved
System::WindowsMobile:ocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder>(void)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@XZ)
referenced in function "public: __cdecl
System::WindowsMobile:ocketOutlook::OutlookSession::OutlookSession(void)"
(??0OutlookSession@PocketOutlook@WindowsMobile@System@@QAA@XZ)
1>System.WindowsMobile.PocketOutlook.obj : error LNK2019: unresolved
external symbol "public: __cdecl System::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder>(class
System::WindowsMobile:ocketOutlook::ContactFolder *)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@PAVContactFolder@PocketOutlook@WindowsMobile@1@@Z)
referenced in function "public: class System::RefPtr<class
System::WindowsMobile:ocketOutlook::ContactFolder> __cdecl
System::WindowsMobile:ocketOutlook::OutlookSession::get_Contacts(void)"
(?get_Contacts@OutlookSession@PocketOutlook@WindowsMobile@System@@QAA?AV?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@4@XZ)
1>Windows Mobile 6 Standard SDK (ARMV4I)\Debug\TestPoom.exe : fatal
error LNK1120: 2 unresolved externals
I don't understand ths missing reference since I am including RefPtr.h
(see below) :
File RefPtr.h
-----------------
#ifndef RefPtr_h
#define RefPtr_h
namespace System{
template<typename T>
class RefPtr
{
public:
~RefPtr();
RefPtr();
RefPtr(const RefPtr<T>& rhs);
RefPtr(T* ptr);
RefPtr<T>& operator=(const RefPtr<T>& rhs);
RefPtr<T>& operator=(T* ptr);
bool operator<(const RefPtr<T>& rhs) const;
bool operator==(const RefPtr<T>& rhs) const;
bool operator==(const T* rhs) const;
bool operator!=(const RefPtr<T>& rhs) const;
bool operator!=(const T* rhs) const;
bool isNull() const;
operator bool() const;
T* operator->() const;
T& operator*() const;
T* get() const;
void Release();
private:
T* m_ptr;
};
} // namespace System
#include "RefPtr.inl"
#endif
File RefPtr.inl
-----------------
namespace System{
template<typename T>
inline
RefPtr<T>::RefPtr(const RefPtr& rhs) : m_ptr(rhs.m_ptr)
{
if(m_ptr)
m_ptr->AddRef();
}
template<typename T>
inline
RefPtr<T>& RefPtr<T>:perator=(const RefPtr<T>& rhs)
{
T* const pNew = rhs.get();
if(m_ptr != pNew)
{
T* const pOld = m_ptr;
if(pNew)
pNew->AddRef();
m_ptr = pNew;
if(pOld)
pOld->Release();
}
return *this;
}
template<typename T>
inline
RefPtr<T>& RefPtr<T>:perator=(T* ptr)
{
if(m_ptr != ptr)
{
if(ptr)
ptr->AddRef();
T* const pOld = m_ptr;
m_ptr = ptr;
if(pOld)
pOld->Release();
}
return *this;
}
template<typename T>
inline
bool RefPtr<T>:perator<(const RefPtr& rhs) const
{
return (m_ptr < rhs.m_ptr);
}
template<typename T>
inline
bool RefPtr<T>:perator==(const RefPtr& rhs) const
{
return (m_ptr == rhs.m_ptr);
}
template<typename T>
inline
bool RefPtr<T>:perator==(const T* rhs) const
{
return (m_ptr == rhs);
}
template<typename T>
inline
bool RefPtr<T>:perator!=(const RefPtr& rhs) const
{
return !(*this == rhs);
}
template<typename T>
inline
bool RefPtr<T>:perator!=(const T* rhs) const
{
return (m_ptr != rhs);
}
template<typename T>
inline
RefPtr<T>:perator bool() const
{
return (m_ptr!=0);
}
template<typename T>
inline
bool RefPtr<T>::isNull() const
{
return (m_ptr == 0);
}
template<typename T>
inline
T* RefPtr<T>::get() const
{
return m_ptr;
}
template<typename T>
inline
T* RefPtr<T>:perator->() const
{
ASSERT(m_ptr!=0);
return m_ptr;
}
template<typename T>
inline
T& RefPtr<T>:perator*() const
{
ASSERT(m_ptr!=0);
return *m_ptr;
}
template<typename T>
inline
RefPtr<T>::~RefPtr()
{
Release();
}
template<typename T>
inline
void RefPtr<T>::Release()
{
if(m_ptr)
{
m_ptr->Release();
m_ptr = 0;
}
}
} //namespace System