Two Bugs of VC++.NET2005 IDE
来源:互联网 发布:阿里云服务器搭建网站 编辑:程序博客网 时间:2024/04/29 20:53
First let’s see a program
/*
Abstract : A program to show polymophism.
Author : Lijie Wang
Environment : Visual C++.NET 2005
History :
*/
#include<iostream>
using namespace std;
class B1
{
public:
virtual void vf1()
{
cout<<"B1::vf1"<<endl;
}
virtual void vf2()
{
cout<<"B1::vf2"<<endl;
}
virtual void vf3()
{
cout<<"B1::vf3"<<endl;
}
void B
};
class B2
{
public:
virtual void vf2()
{
cout<<"B2::vf2"<<endl;
}
virtual void vf3()
{
cout<<"B2::vf3"<<endl;
}
virtual void vf4()
{
cout<<"B2::vf4"<<endl;
}
void B
};
class D : public B1, public B2
{
public:
void vf1() //overide B1::vf1 and B2::vf1
{
cout<<"D::vf1"<<endl;
}
void vf3()
{
cout<<"D::vf3"<<endl;
}
virtual void vf5() //additional virtual function
{
cout<<"D::vf5"<<endl;
}
void Df() //non virtual function
{
cout<<"D::Df"<<endl;
}
void Set_A(int n)
{
a = n;
cout<<"D::A="<<a<<endl;
}
private:
int a;
};
void main()
{
D d;
B1 b1;
B2 b2;
B1 *pb1 = &d; //pb1 point to the B1-sub-object of D
B2 *pb2 = &d; //pb1 point to the B2-sub-object of D
d.vf3();
d.vf5();
b1.vf1();
b2.vf3();
pb1->vf1(); //danymic binding
pb1->vf2(); //danymic binding
pb1->vf3();
dynamic_cast<D*>(pb1)->Set_A(1);
pb2->vf2();
pb2->vf3();
pb2->vf4();
dynamic_cast<D*>(pb1)->vf5();
}
The class diagram of this program is shown in Fig 1.
Fig 1. Class Diagram
The structure of d object can be found from the Watch Window while debugging, just like Fig 2:
Fig 2. Structure of d Object
We can find from the structure of the d object that it includes a B1 sub-object and a B2 sub-object with a __vfptr in each one. From the vftables we can see that D::vf1 has overridden the B1::vf3 and B2::vf3, just according to our expectation. But we can not find the new virtual function D::vf
Let’s see the address of d.vf5 from the Watch Window:
Fig 3. Address of d.vf5
This indicates that the address of d.vf5 is 0x00411208.
Then we can find the address of the vftable of B1 sub-object or say d.B1.__vfptr from the Watch Window:
Fig 4. Address of d.B1.__vfptr
So the address of the B1.__vfptr of d is 0x00417744, then we turn to the Memory Window to check what is stored in the vftable of B1 sub-object:
Fig 5. Memory content from of vftable of B1 sub object of d
From the picture above we can see that the four successive words stored in the vftable of B1 sub-object are: 0x004111e5, 0x00411091, 0x004111bd, 0x00411208. 0x00411208 is just the address of d.vf5, this indicates that d.vf5 is actually inserted in the end of the first sub-object vftable of d, here is vftable of B1 sub-object. But we can not find it from Fig 2. So I think this is a bug of the VC++.NET IDE (I use VC++.NET 2005).
Then the we modify the program by replacing each vf* function by f*. Then the structure of the d object in the Watch Window is shown in the Fig 6.
Fig 6. Structure of d Object After Modification
- Two Bugs of VC++.NET2005 IDE
- fwnx -- working bugs in the two week of osp
- VC.NET2005读字符串
- VC++.Net2005的一些常识
- vc.net2005+access实现天气预报。
- the analyze of bugs,the list of bugs
- 最常用的vc/vc.net2005快捷键
- Some experienced note of bugs
- all of these are bugs!
- 这是VC++.NET2005的问题吗?
- VC.net2005下,字符集的问题...
- vc ++.net2005 managed unmanaged mixing code
- VC++.Net2005的一些常识(转)
- VC++.Net2005---叶帆学习初体验
- BUGS
- bugs
- f**king the two bugs from Visual studio!
- VC-IDE tips
- 吃饭
- 无法找到"WebUIValidation.js"的终极解决方法
- ASProtect Features
- 如何提高Hibernate 3 启动速度
- 关于计算机学习的使命感
- Two Bugs of VC++.NET2005 IDE
- 一个程序员的编码心得(http://www.esmerel.com/wagons/rob/rules.html)
- 秋天,真美
- Web Service“四长两短”
- Java实现汉字转换为拼音
- 周总理回答外国记者超牛语录.
- 提高网页下载速度的两种方法
- 多边形裁剪
- 【转】C/C++编译器