英文好的懂c++的来帮小弟我翻译一下这段讲的是什么`
英文好的懂c++的来帮我翻译一下这段讲的是什么``
Using the version of compare()with the pass-by-value parameter,
the copy constructor is called because a copy of the argument
is passed to the function.
Using the version with the reference parameter a reference
to the object is passed to the function so no constructor call
is necessary.
You cannot overload a function with a reference parameter with
a function that has a non-reference parameter because the
compiler cannot tell which function should be called in any
particular instance.
着段讲的知识是什么`麻烦帮我翻译一下``
------解决方案--------------------
又是关于传值和传引用的问题啊。
最后一段是讲不能用非引用参数的函数去重载带引用参数的函数(废话-_-!),否则编译器无法分辨是调用引用参数还是非引用参数的函数。
这个一般书上都会讲吧。
------解决方案--------------------
在使用“传值”版本的compare()方法时,拷贝构造函数会被调用,这是因为参数的一份拷贝被传递给了该方法。
当使用参数为引用的compare()方法时,只是对象的引用被传递了,构造函数无需调用。
一个本来以‘引用’为参数的函数,你不能提供一个不使用‘引用’为参数的重载版本,因为编译器不知道去调用哪个版本函数。
Using the version of compare()with the pass-by-value parameter,
the copy constructor is called because a copy of the argument
is passed to the function.
Using the version with the reference parameter a reference
to the object is passed to the function so no constructor call
is necessary.
You cannot overload a function with a reference parameter with
a function that has a non-reference parameter because the
compiler cannot tell which function should be called in any
particular instance.
着段讲的知识是什么`麻烦帮我翻译一下``
------解决方案--------------------
又是关于传值和传引用的问题啊。
最后一段是讲不能用非引用参数的函数去重载带引用参数的函数(废话-_-!),否则编译器无法分辨是调用引用参数还是非引用参数的函数。
这个一般书上都会讲吧。
------解决方案--------------------
在使用“传值”版本的compare()方法时,拷贝构造函数会被调用,这是因为参数的一份拷贝被传递给了该方法。
当使用参数为引用的compare()方法时,只是对象的引用被传递了,构造函数无需调用。
一个本来以‘引用’为参数的函数,你不能提供一个不使用‘引用’为参数的重载版本,因为编译器不知道去调用哪个版本函数。