一个类可以有多个拷贝构造函数,那么怎么决定调用哪个复制构造函数呢?

愚蠢的萝卜 2016-06-19 12:33:20
C++初学
在书上看到:一个类至少有 一个拷贝构造函数;事实上,可以有多个。
而且刚刚看到以下代码:
class ROSCPP_DECL NodeHandle
{
public:
/**
* \brief Constructor
*
* When a NodeHandle is constructed, it checks to see if the global
* node state has already been started. If so, it increments a
* global reference count. If not, it starts the node with
* ros::start() and sets the reference count to 1.
*
* \param ns Namespace for this NodeHandle. This acts in addition to any namespace assigned to this ROS node.
* eg. If the node's namespace is "/a" and the namespace passed in here is "b", all
* topics/services/parameters will be prefixed with "/a/b/"
* \param remappings Remappings for this NodeHandle.
* \throws InvalidNameException if the namespace is not a valid graph resource name
*/
NodeHandle(const std::string& ns = std::string(), const M_string& remappings = M_string());
/**
* \brief Copy constructor
*
* When a NodeHandle is copied, it inherits the namespace of the
* NodeHandle being copied, and increments the reference count of
* the global node state by 1.
*/
NodeHandle(const NodeHandle& rhs);
/**
* \brief Parent constructor
*
* This version of the constructor takes a "parent" NodeHandle, and is equivalent to:
\verbatim
NodeHandle child(parent.getNamespace() + "/" + ns);
\endverbatim
*
* When a NodeHandle is copied, it inherits the namespace of the
* NodeHandle being copied, and increments the reference count of
* the global node state by 1.
*
* \throws InvalidNameException if the namespace is not a valid
* graph resource name
*/
NodeHandle(const NodeHandle& parent, const std::string& ns);
/**
* \brief Parent constructor
*
* This version of the constructor takes a "parent" NodeHandle, and is equivalent to:
\verbatim
NodeHandle child(parent.getNamespace() + "/" + ns, remappings);
\endverbatim
*
* This version also lets you pass in name remappings that are specific to this NodeHandle
*
* When a NodeHandle is copied, it inherits the namespace of the NodeHandle being copied,
* and increments the reference count of the global node state
* by 1.
* \throws InvalidNameException if the namespace is not a valid graph resource name
*/
NodeHandle(const NodeHandle& parent, const std::string& ns, const M_string& remappings);
/**
* \brief Destructor
*
* When a NodeHandle is destroyed, it decrements a global reference
* count by 1, and if the reference count is now 0, shuts down the
* node.
*/


NodeHandle(const NodeHandle& rhs)
显然是NodeHandle的拷贝构造函数,但是
NodeHandle(const NodeHandle& parent, const std::string& ns), NodeHandle(const NodeHandle& parent, const std::string& ns, const M_string& remappings)
这两个从注释来看,应该也是起拷贝作用。所以就在想如果一个类有多个拷贝构造函数,那么编译器是怎么判断调用哪个拷贝构造函数的呢?
...全文
709 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
NodeHandle(const NodeHandle& rhs); 拷贝只有这1个 其他的都是构造函数
ooolinux 2016-06-19
  • 打赏
  • 举报
回复
根据调用(构造)时的函数实参
愚蠢的萝卜 2016-06-19
  • 打赏
  • 举报
回复
引用 1 楼 u010165006 的回复:
根据调用(构造)时的函数实参
谢谢

65,180

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧