⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctor30.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
字号:
#include "fail.h"

struct S {
    int s;
    S( int );
    S( S const & );
    ~S();
};

int c;

S::S( int s ) : s(s) {
    ++c;
}
S::S( S const &s ) : s(s.s) {
    if( this == &s ) fail(__LINE__);
    ++c;
}
S::~S(){
    --c;
    if( c < 0 ) fail(__LINE__);
    s = -1;
}

void check( S const &x, unsigned line ) {
    if( c != 2 ) fail( line );
}

// 5.2.3 S(x) == (S)x
// 5.2.8 S -> S is an implicit cast
// 4 - equivalent to: S t(x); with result equal to 't'
int main() {
    S x(__LINE__);
    check( S(x), __LINE__ );
    if( c != 1 ) fail(__LINE__);
#if __WATCOM_REVISION__ >= 8
    check( (S)x, __LINE__ );
    if( c != 1 ) fail(__LINE__);
#endif
    _PASS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -