月度归档:2007年06月

接电话

爸爸打电话回去给笑笑,笑笑接到电话就说:"爸爸给我买个DVD吧,那个VCD梦水乡都放不出来的",说完就把电话撂下了。好几天都是这句话。 梦水乡是兴化的市歌,家里有张DVD的碟,笑笑特别爱听这歌,以前在家里是用电脑放的,在北京也用DVD机放过。但现在家里的电脑笑笑叔叔老用着,另外只有台VCD的机器,放不出来,笑笑想听啊,爷爷奶奶就说让爸爸给你买个DVD吧,所以每次打电话都不忘记提醒爸爸一下,呵呵

过了几天,变成:"爸爸给我买个摩托车吧",可能是看到楼下的其他小朋友有小车骑了;又过了几天,变成:"我把叔叔的眼睛弄坏了,爸爸给我赔给叔叔吧…"

R6025 – pure virtual function call

今天的一个程序出了 R6025 – pure virtual function call 错误,主要原因是在基类的构造函数中调用了纯虚函数。
1. 如果不是纯虚函数,没问题。
2. 如果构造函数直接调用纯虚函数,链接时会出错。只有通过一个其它成员函数转调一下。

下面是一个简化的例子:
class CBase
{
public:
CBase() { func2(); }
virtual void func() = 0;
void func2()
{
func();
}
};

class CDrived : public CBase
{
public:
CDrived() { }
virtual void func() { printf(“hello”); }
};

int _tmain(int argc, _TCHAR* argv[])
{
CDrived * d = new CDrived();

return 0;
}

typeid

class Base
{
public:
void vvfunc() {}
};

class Derived : public Base
{

};

int _tmain(int argc, _TCHAR* argv[])
{
Derived* pd = new Derived;
Base* pb = pd;
cout << typeid( pb ).name() << endl; //prints "class Base *" cout << typeid( pd ).name() << endl; //prints "class Derived *" try { // Base * pp = NULL; // cout << typeid( *pp ).name() << endl; cout << typeid( *pb ).name() << endl; //prints "class Derived" cout << typeid( *pd ).name() << endl; //prints "class Derived" } catch (std::__non_rtti_object e) { cout << "__non_rtti_object" << endl; } catch (std::bad_typeid e) { cout << "bad_typeid exception" << endl; } delete pd; return 0; }

Visual C++ .NET下,如果/GR 未打开,这个程序仍然成功打印.

但如果 public: virtual void vvfunc(), 则 typeid( *pb ), typeid( *pd )的会错误,抛出__non_rtti_object异常。

如果上面注释的两句打开,则会跑出__bad_typeid异常。

__non_rtti_object继承自__bad_typeid.