这个程序的输出是什么?为什么? [英] What is the output of this program? and why?
问题描述
#include" stdafx.h"
#include< stdio.h>
#define output(x)printf(#x" \ r \ n"); fflush(stdout)
class CMyBase
{
public:
CMyBase()
{
输出(CMyBase());
f(* this);
}
CMyBase(CMyBase& b)
{
输出(CMyBase(副本));
}
CMyBase(int i){output(CMyBase(int)); } $ / $
虚拟CMyBase f(CMyBase& b){output(CMyBase :: f());返回b; }
};
class CDerived:public CMyBase
{
public:
CDerived()
{
输出(CDerived());
}
CDerived(CMyBase其他)
{
输出(CDerived());
}
虚拟CMyBase f(CMyBase& ; b){输出(第一);返回b; } $ / $
虚拟CMyBase f(CMyBase b)const {输出(秒);返回b; }
~CDerived()
{
输出(~CDerived);
}
};
int main(int argc,char * argv [])
{
CDerived a;
CMyBase * p =& a;
CDerived b = a;
p-> f(b);
b = a;
af(5);
af(b);
< ka ********* @ gmail.com>在消息中写道
新闻:11 ********************** @ g47g2000cwa.googlegr oups.com ...
您认为输出应该是什么?
-Howard
我不确定,
但我在想
CDerived()5
ka ********* @ gmail.com 写道:#include" stdafx .h"
[...]
该程序不完整,它至少包含一个非标准的
构造因此它甚至不会编译。此外,阅读常见问题5.2。
V
-
请通过邮件回复时从我的地址中删除资金
#include "stdafx.h"
#include <stdio.h>
#define output( x ) printf( #x "\r\n" );fflush( stdout )
class CMyBase
{
public:
CMyBase()
{
output( CMyBase() );
f(*this);
}
CMyBase( CMyBase& b )
{
output( CMyBase( copy ) );
}
CMyBase( int i ) { output( CMyBase( int ) ); }
virtual CMyBase f(CMyBase& b) { output( CMyBase::f() ); return b; }
};
class CDerived : public CMyBase
{
public:
CDerived()
{
output( CDerived() );
}
CDerived( CMyBase other )
{
output( "CDerived()" );
}
virtual CMyBase f(CMyBase& b) { output( first ); return b; }
virtual CMyBase f(CMyBase b) const { output( second ); return b; }
~CDerived()
{
output(~CDerived);
}
};
int main(int argc, char* argv[])
{
CDerived a;
CMyBase* p = &a;
CDerived b = a;
p->f(b);
b = a;
a.f( 5 );
a.f( b );
<ka*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
What do YOU think the output should be?
-Howard
I am not sure,
but I am thinking
CDerived() 5
ka*********@gmail.com wrote:#include "stdafx.h"
[...]
The program is incomplete, it contains at least one non-standard
construct and therefore it won''t even compile. Also, read FAQ 5.2.
V
--
Please remove capital As from my address when replying by mail
这篇关于这个程序的输出是什么?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!