qysh

C++中遇到同名函数问题,可以使用命名空间解决

#include "stdafx.h"
#include <iostream>
using std::cout; //使用命名空间std中的cout
using std::endl;

namespace mycode //在自己的mycode命名空间中定义foo()函数
{
void foo()
{
cout<<"foo"<<endl;
}
}

void foo() //定义foo()函数
{
cout<<"another foo"<<endl;
}

int main()
{
mycode::foo(); //调用mycode命名空间中的foo()函数
foo();
system("pause");
}

 

此代码运行结果为:

posted on 2011-11-17 14:15  qysh  阅读(843)  评论(0编辑  收藏  举报

导航