
程序代码:
#include <typeinfo>
#include <iostream>
#include <string>
class Base
{
public:
Base(const std::string &logInfo)
{
CreateLogInfo(logInfo);
}
virtual std::string CreateLogInfo(const std::string &logInfo)
{
std::cout << typeid(*this).name() << std::endl;
return logInfo;
}
};
class Derive:public Base
{
public:
Derive (const std::string& logInfo):Base(CreateLogInfo(logInfo))
{
std::cout << typeid(*this).name() << std::endl;
}
virtual std::string CreateLogInfo(const std::string logInfo)
{
//std::cout << typeid(*this).name() << std::endl;
return logInfo;
}
};
int main()
{
Derive obj("obj");
return 0;
}