Which function is called?
来源:互联网 发布:九章算法班 百度云 编辑:程序博客网 时间:2024/05/21 16:57
class b
{
public:
virtual void mf( int p ) ;
} ;
void b::mf( int p )
{
cout << "member function mf in b called, "
<< "value of parameter is " << p << endl ;
}
class d : public b
{
public:
void mf( double p ) ;
} ;
void d::mf( double p )
{
cout << "member function mf in d called, "
<< "value of parameter is " << p << endl ;
}
void main()
{
b *ptr ;
ptr = new d ;
ptr->mf( 1.5 ) ;
}
Think what's the output. The output is:
member function mf in b called, value of parameter is 1
The decision process by the complier is as following:
1. In main function, a pointer ptr is declared whose type is b*.
2. An object d of class d is allocated and ptr point to the object d.
3. As the type of ptr is b*, the program begin to find the function void mf(double p) defined in class b.
4. There is no function void mf(double p) in class b, the program convert float(1.5) to int(1), and then call the function void mf(int p).
- Which function is called?
- Which function is called when use virtual function.
- Why Schduler function is not called?
- 98.Which statement is true regarding the COALESCE function?
- Question 8: In which of the following scenarios is a Copy Constructor called or invoked?
- How module init function is called when the module is loaded
- Pure virtual function called
- pure virtual function called
- Pure Virtual Function Called
- Javascript Anonymous Function Called
- Pure virtual function called
- How native function is called in…
- call different method with the same name, parameters and return value, select which one is called using const symbol
- which-function-mode
- A function that corrects the "ActionDay" fields from market quotes which is delivered by CTP.
- getReader() is called by
- C++: Pure Virtual Function Called
- Which is more important?
- VB.NET中实现IEnumerator接口
- Oracle8 数据类型
- 菜鸟学脱壳
- Borlank开放JBuilder源代码
- 扑克21点作弊算法【综合文 FreeXploiT收集整理】仅供研究,不要非法使用
- Which function is called?
- Which function is called when use virtual function.
- 吃疯了穷怕了
- 气象相关网页
- 数字的全排列
- Linux下Apache,Php,Mysql配置
- Struts秘籍之起式第1.1式:下载Struts
- 使用24位位图作为OpenGL的材质贴图
- 程序员与妓女