当前在线人数16853
首页 - 分类讨论区 - 电脑网络 - 葵花宝典版 -阅读文章
未名交友
[更多]
[更多]
文章阅读:Re: VC里面的stl支持是不是很弱?
[同主题阅读] [版面: 葵花宝典] [作者:thrust] , 2004年07月14日16:46:10
thrust
进入未名形象秀
我的博客
[上篇] [下篇] [同主题上篇] [同主题下篇]

发信人: thrust (哼哼的多隆猪), 信区: Programming
标  题: Re: VC里面的stl支持是不是很弱?
发信站: Unknown Space - 未名空间 (Wed Jul 14 16:57:05 2004), 转信

Yes let me tell you why this worked but directly using PointGeneric3D<short>
doesn't.
To make it simple, I will rename your class (template doesn't matter):
PointGeneric<short> -> A
PointGeneric3D<short> -> B
PointInt -> C

So you have
class A {
A() {}
A(short xx, short yy) {...}            // *******first
virtual ~A() {}
short x, y;
};
class B : public A {
B() {}
short z;
B(short xx, short yy, short zz) : z(zz) { this -> A::A(xx,yy); } // ***second
// I even didn't know you could write above, crap
B(short ...) : A(xx,yy), z(zz) {} // ******third
};
class C : public B {
C(short .....) { /* something */ } // *****fourth
};

Now, what does ctors do? for first one, it does
{ this->vptr=A::vtbl; /* the real content */ }
for second one (wrong one), it does
{ z=zz; this->A::A(); this->vptr=B::vtbl;
  this->A::A(xx,yy);
}
for third one (correct one), it does
{ this->A::A(xx,yy); z=zz; this->vptr=B::vtbl; }
See the difference? the third one, correctly set the vptr to B's vtbl,
while the second one, finally set the vptr to A's vtbl.

Now the fourth one.
{ /* do the initializers */
  this->vptr=C::vtbl;
  /* something */
}
So finally it used the vtbl of C. The fault was covered so it looks correct.


【 在 observer (笑看人生) 的大作中提到: 】
: By the way, my original way of calling ctor worked fine until I do the
: following change:
: // class PointInt : public PointGeneric3D<short>
: //{
: // ...
: // }
: typedef PointGeneric3D<short> PointInt;


--
贵姓阿你? 多隆哪有你这么帅阿?

※ 修改:.thrust 于 Jul 14 16:58:15 修改本文.[FROM: 128.205.]
※ 来源:.Unknown Space - 未名空间 mitbbs.com.[FROM: 128.205.]

[上篇] [下篇] [同主题上篇] [同主题下篇]
[转寄] [转贴] [回信给作者] [修改文章] [删除文章] [同主题阅读] [从此处展开] [返回版面] [快速返回] [收藏] [举报]
 
回复文章
标题:
内 容:

未名交友
将您的链接放在这儿

友情链接


 

Site Map - Contact Us - Terms and Conditions - Privacy Policy

版权所有,未名空间(mitbbs.com),since 1996