由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - namespace 问题
相关主题
请问关于overloading <<[合集] 关于template和inheritance的问题请教
a simple question for C++ classcompare double to float
请问一个exception题目[合集] C++问题(copy constructor)
两个继承问题问一个简单的C++问题
为什么我看不懂下面的code,是不是水平还不够?一个指向指针的指针的引用?
C++疑问问个char*的问题
two c++ interview questions! (转载)数组弱问
请教一个作用域的问题[合集] 关于构造函数
相关话题的讨论汇总
话题: std话题: swap话题: namespace话题: const话题: endl
进入Programming版参与讨论
1 (共1页)
A**u
发帖数: 2458
1
#include
#include
using namespace std;
namespace S{
class A{
};
void swap(const A& x, const A& y){
std::cout << "A swap" << std::endl;
}
}
int main()
{
S::A x;
S::A y;
swap(x,y);
//S::swap(x,y);
std::cout << "fishing" << std::endl;
return 0;
}
这个code里, namespace S里的 swap 比 std里的swap specific
为啥 gcc 编译后,调用std版本呢
t****t
发帖数: 6806
2
because std::swap() accept (A&, A&) while S::swap() accept (const A&, const
A&). you called with (A&, A&). function overloading selects std::swap().

【在 A**u 的大作中提到】
: #include
: #include
: using namespace std;
: namespace S{
: class A{
: };
: void swap(const A& x, const A& y){
: std::cout << "A swap" << std::endl;
: }
: }

A**u
发帖数: 2458
3
大牛 谢谢啦
才想起来 type&比 const type&优先

const

【在 t****t 的大作中提到】
: because std::swap() accept (A&, A&) while S::swap() accept (const A&, const
: A&). you called with (A&, A&). function overloading selects std::swap().

B******5
发帖数: 4676
4
这些问题也太细节了。。。

【在 A**u 的大作中提到】
: 大牛 谢谢啦
: 才想起来 type&比 const type&优先
:
: const

t****t
发帖数: 6806
5
library interface design is not an easy task from the beginning, no matter
what language you use. you want to cover a lot of details: efficiency,
readability, encapsulation, robust, adaptation, decoupling, ... beginners
may cover one or several, but you need experience to cover all of them.

【在 B******5 的大作中提到】
: 这些问题也太细节了。。。
k****5
发帖数: 546
6
big cow, can't understand many details of language(c/c++) standard, what to
do?

【在 t****t 的大作中提到】
: library interface design is not an easy task from the beginning, no matter
: what language you use. you want to cover a lot of details: efficiency,
: readability, encapsulation, robust, adaptation, decoupling, ... beginners
: may cover one or several, but you need experience to cover all of them.

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] 关于构造函数为什么我看不懂下面的code,是不是水平还不够?
C++菜问: 怎么这样也可以?C++疑问
c++之极弱问two c++ interview questions! (转载)
请教一个c++ reference问题请教一个作用域的问题
请问关于overloading <<[合集] 关于template和inheritance的问题请教
a simple question for C++ classcompare double to float
请问一个exception题目[合集] C++问题(copy constructor)
两个继承问题问一个简单的C++问题
相关话题的讨论汇总
话题: std话题: swap话题: namespace话题: const话题: endl