Z
zrajbun
Hi,
I have the following code.
struct Object
{
int m_id;
void setId(int const id)
{
m_id = id;
}
};
// version 1
template < class T >
void resetId(T &obj, int const id)
{
obj.setId(id);
}
// version 2
template < class T >
void resetId(boost::shared_ptr < T > const &obj, int const id)
{
obj->setId(id);
}
int main()
{
Object obj1;
resetId(obj1, 1); // calls version 1
boost::shared_ptr < Object > obj2;
resetId(obj2, 2); // This calls version 1 too
}
This is with GCC 3.2.3...
How can I make sure that the call "resetId(obj2, 2)" calls version 2
that is overloaded for shared_ptr objects.
I have the following code.
struct Object
{
int m_id;
void setId(int const id)
{
m_id = id;
}
};
// version 1
template < class T >
void resetId(T &obj, int const id)
{
obj.setId(id);
}
// version 2
template < class T >
void resetId(boost::shared_ptr < T > const &obj, int const id)
{
obj->setId(id);
}
int main()
{
Object obj1;
resetId(obj1, 1); // calls version 1
boost::shared_ptr < Object > obj2;
resetId(obj2, 2); // This calls version 1 too
}
This is with GCC 3.2.3...
How can I make sure that the call "resetId(obj2, 2)" calls version 2
that is overloaded for shared_ptr objects.