ns23.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 44 行

C
44
字号
#include "fail.h"

#ifdef __WATCOM_NAMESPACE__
int which;

namespace A {
    void f(int x) {
	if( x != 'a' ) _fail;
	which |= 1;
    }
}

using A::f;              // f is a synonym for A::f;
	       		// that is, for A::f(int).
namespace A {
    void f(char x ) {
	if( x != 'a' ) _fail;
	which |= 2;
    }
}

void foo() {
    which = 0;
    f('a');          // calls f(int),
    if( which != 1 ) _fail;
}                        // even though f(char) exists.

void bar() {
    using A::f;      // f is a synonym for A::f;
		   // that is, for A::f(int) and A::f(char).
    which = 0;
    f('a');          // calls f(char)
    if( which != 2 ) _fail;
}

int main() {
    foo();
    bar();
    _PASS;
}
#else
ALWAYS_PASS
#endif

⌨️ 快捷键说明

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