SmartPtr Issues

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.PocketOutlook.obj : error LNK2019: unresolved
external symbol "public: __cdecl System::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder>(void)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@XZ)
referenced in function "public: __cdecl
System::WindowsMobile::pocketOutlook::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::pocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder>(class
System::WindowsMobile::pocketOutlook::ContactFolder *)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@PAVContactFolder@PocketOutlook@WindowsMobile@1@@Z)
referenced in function "public: class System::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder> __cdecl
System::WindowsMobile::pocketOutlook::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>::eek: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>::eek: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>::eek:perator<(const RefPtr& rhs) const
{
return (m_ptr < rhs.m_ptr);
}

template<typename T>
inline
bool RefPtr<T>::eek:perator==(const RefPtr& rhs) const
{
return (m_ptr == rhs.m_ptr);
}

template<typename T>
inline
bool RefPtr<T>::eek:perator==(const T* rhs) const
{
return (m_ptr == rhs);
}

template<typename T>
inline
bool RefPtr<T>::eek:perator!=(const RefPtr& rhs) const
{
return !(*this == rhs);
}

template<typename T>
inline
bool RefPtr<T>::eek:perator!=(const T* rhs) const
{
return (m_ptr != rhs);
}

template<typename T>
inline
RefPtr<T>::eek: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>::eek:perator->() const
{
ASSERT(m_ptr!=0);
return m_ptr;
}

template<typename T>
inline
T& RefPtr<T>::eek: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
 
M

Michael DOUBEZ

mosfet a écrit :
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::ContactFolder>::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder>(void)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@XZ)
referenced in function "public: __cdecl
System::WindowsMobile::pocketOutlook::OutlookSession::OutlookSession(void)"
(??0OutlookSession@PocketOutlook@WindowsMobile@System@@QAA@XZ)


Your RefPtr<T> is not default-constructible.

You can solve it by using a default pointer value in your RefPtr header
(see bellow) or by explicitly initializing it to NULL.
1>System.WindowsMobile.PocketOutlook.obj : error LNK2019: unresolved
external symbol "public: __cdecl System::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder>::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder>(class
System::WindowsMobile::pocketOutlook::ContactFolder *)"
(??0?$RefPtr@VContactFolder@PocketOutlook@WindowsMobile@System@@@System@@QAA@PAVContactFolder@PocketOutlook@WindowsMobile@1@@Z)
referenced in function "public: class System::RefPtr<class
System::WindowsMobile::pocketOutlook::ContactFolder> __cdecl
System::WindowsMobile::pocketOutlook::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* ptr=NULL);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top