File1.cpp
#include <vcl.h>
namespace myfun // 命名空间myfun
{
UnicodeString fun() // 定义在 myfun 中
{
return L"使用myfun中的fun()";
}
};
namespace yourfun // 命名空间yourfun
{
UnicodeString fun() // 定义在 yourfun 中
{
return L"使用yourfun中的fun()";
}
};
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include "File1.cpp"
using namespace myfun; // 主要用 myfun
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Clear();
Memo1->Lines->Add(fun()); // myfun::fun();
Memo1->Lines->Add(yourfun::fun()); // 临时用 yourfun
}
//---------------------------------------------------------------------------
输出效果