In gdb, print command prints the contents of the variable. If you are using any IDE for C++, eg. Netbeans, Eclipse, VC++ then pointing on the variable shows the content.
EDIT: See if the below code is what you are looking for.
#include <string>
using std::string;
#define magic_string(a) #a
template<typename T>
class Object_C
{
private:
virtual string toString_Impl()
{
return magic_string(T);
}
public:
Object_C(void)
{
}
virtual ~Object_C(void)
{
}
string toString()
{
return toString_Impl();
}
};
class Base_C :
public Object_C<Base_C>
{
private:
string toString_Impl()
{
char str[80] = "";
sprintf_s(str, 79, "Base.x:%d\n", x_);
return string(str);
}
private:
int x_;
public:
Base_C(int x = 0) : x_(x) { }
~Base_C(void);
};
void ToStringDemo()
{
Base_C base;
cout << base.toString() << endl;
}