How to return a Null pointer for shared_ptr

Hi, I defined a shared_ptr in to a map table. How can I return a NULL pointer in a function to search the table if it is not found as following example? typedef shared_ptr<int> IntPtr; typedef std::map<std::string IntPtr> MapTable; MapTable mt; IntPtr search(const std::string& key) { MapTable::const_iterator it = mt.find(key); if (it == mt.end()) { return NULL; // can't compile it?? } return it->second; } Thank you. Kind regards, Jupiter

Use return IntPtr(); This will also return NULL if IntPtr is a typedef of a raw pointer type. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode On Tue, Dec 1, 2009 at 5:12 PM, hce <webmail.hce@gmail.com> wrote:
Hi,
I defined a shared_ptr in to a map table. How can I return a NULL pointer in a function to search the table if it is not found as following example?
typedef shared_ptr<int> IntPtr; typedef std::map<std::string IntPtr> MapTable;
MapTable mt;
IntPtr search(const std::string& key) { MapTable::const_iterator it = mt.find(key); if (it == mt.end()) { return NULL; // can't compile it?? } return it->second; }
Thank you.
Kind regards,
Jupiter _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

IntPtr search(const std::string& key) { IntPtr i; MapTable::const_iterator it = mt.find(key); if (it != mt.end()) { i = it->second; // can't compile it?? } return i; } On Tue, Dec 1, 2009 at 8:12 PM, hce <webmail.hce@gmail.com> wrote:
Hi,
I defined a shared_ptr in to a map table. How can I return a NULL pointer in a function to search the table if it is not found as following example?
typedef shared_ptr<int> IntPtr; typedef std::map<std::string IntPtr> MapTable;
MapTable mt;
IntPtr search(const std::string& key) { MapTable::const_iterator it = mt.find(key); if (it == mt.end()) { return NULL; // can't compile it?? } return it->second; }
Thank you.
Kind regards,
Jupiter _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Emil Dotchevski
-
hce
-
Shane Baker