1

Question

I have a class, I want it have a file scope. Such as the static function in cpp file.

static void myFun();
static void myFun()
{

}

Why I want this?

I have many test file, such as test_A.cpp, test_B.cpp, test_C.cpp.

Each cpp file may contain the class X for it self. X is used for test stub, or mocker class.

If a executable file have contain these cpp files, the class X is multiple defined and it is ambigous.

So I wonder is there any way to let the class X have file scope.

I know we can avoid thses problem by add namespace to cover X or rename class X into X_A, X_B, X_C is OK. But it looks verbose.

If a class can have file scope, it is more elagent.

Any suggestions? Thanks for your time.

Xu Hui
  • 1,213
  • 1
  • 11
  • 24

0 Answers0