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.
|
|