假设我有这个功能:
void my_test()
{
A a1 = A_factory_func();
A a2(A_factory_func());
double b1 = 0.5;
double b2(0.5);
A c1;
A c2 = A();
A c3(A());
}
Run Code Online (Sandbox Code Playgroud)
在每个分组中,这些陈述是否相同?或者在某些初始化中是否有额外的(可能是可优化的)副本?
我见过有人说过这两件事.请引用文字作为证据.还请添加其他案例.
标题说明了一切.但是,请string作为任何课程的占位符.
std::string s1("hello"); // construct from arguments
std::string s2 = "hello"; // ???
std::string s3; // construct with default values
s3 = "hello"; // assign
Run Code Online (Sandbox Code Playgroud)
我想知道声明s2是否与for s1或for 相同s3.
c++ initialization variable-assignment copy-constructor assignment-operator