Some errors in your code:
To the typeid usage.. if you're trying to use typeid to return dynamically the name of the class a pointer is referring to (runtime), you should use something like
#include <iostream>
#include <typeinfo>
using namespace std;
class O {
public:
virtual void vfunction() // Just one virtual function in the base to make the derived polymorphic
{
cout << "hello";
}
};
class C : public O
{
public:
C() {};
};
int main()
{
// your code goes here
O* varb = new C(); // Declare an O* pointer to C
cout << typeid(*varb).name(); // This will print out "C", runtime info
cout << typeid(varb).name(); // This will print out "O*"
return 0;
}
http://ideone.com/K2RGd5
And keep in mind that a class needs to be polymorphic (that is, to inherit from a base class with virtual functions) in order for typeid to return the runtime class it is pointing to when dereferencing the pointer.
Some more information here: https://stackoverflow.com/a/11484105/1938163
Notice: in the code above, if you're using gcc, you might see different class names than the original you used.. that's custom-defined by gcc due to name mangling and if you want real code names to show up you should use something like
#include <iostream>
#include <typeinfo>
#include <cxxabi.h> // Needed to demangle in gcc
using namespace std;
class O {
public:
virtual void vfunction()
{
cout << "hello";
}
};
class C : public O
{
public:
C() {};
};
int main() {
// your code goes here
O* varb = new C();
int status;
// Demangle symbols
cout << __cxxabiv1::__cxa_demangle( typeid(*varb).name(), nullptr, 0, &status ); << endl;
cout << __cxxabiv1::__cxa_demangle( typeid(varb).name(), nullptr, 0, &status );
return 0;
}