以下两个语句在语义上是否相同?
#1 person p("Rahul", 20);
#2 person const &p = person("Rahul", 20);
编辑:
对不起,我的意思是询问以下两者在语义上是否相同:
#1 person const p("Rahul", 20);
#2 person const &p = person("Rahul", 20);
Are the following two statements semantically same?
#1 person p("Rahul", 20);
#2 person const &p = person("Rahul", 20);
EDIT:
Sorry, I meant to ask whether the following two are semantically same:
#1 person const p("Rahul", 20);
#2 person const &p = person("Rahul", 20);
最满意答案
他们不是。 然而,这种区别仅受第二种情况需要C ++ 03可访问的拷贝构造函数的影响(即使拷贝构造函数调用实际上没有完成)
// works with #1 fails with #2 struct f1 { f1(string, int); private: f1(f1 const&); };They are not. However, the difference are affected only by the fact that the second case needs a copy constructor to be accessible in C++03 (even if the copy constructor call is not actually done)
// works with #1 fails with #2 struct f1 { f1(string, int); private: f1(f1 const&); };更多推荐
发布评论