ret07.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 47 行
C
47 行
#include "fail.h"
int ctors;
struct S {
int a;
~S();
S(int=0);
S(S const &);
};
S::S( int x ) : a(x) {
++ctors;
}
S::~S() {
a = -1;
--ctors;
if( ctors < 0 ) fail(__LINE__);
}
S::S( S const &s ) : a(s.a) {
++ctors;
}
S do_add( S const &x, S const &y )
{
return( S( x.a + y.a ) );
}
S add( S const &x, S const &y )
{
return do_add( x, y );
}
int main()
{
{
S x( add( S(2), S(3) ) );
if( x.a != 5 ) fail(__LINE__);
S y( add( S(4), S(5) ) );
if( y.a != 9 ) fail(__LINE__);
}
if( ctors != 0 ) fail(__LINE__);
_PASS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?