I am using protobuf, and I was assigning a const reference to another reference, this seems to trigger the copy constructor if I use {}
, but works fine if I use ()
.
For example,
// Protobuf Messages
message Test {
string x = 1;
}
message List {
repeated Test tests = 1;
}
int main()
{
List l {};
const google::protobuf::RepeatedPtrField<Test>& a = l.tests();
const google::protobuf::RepeatedPtrField<Test>& b = a; // 1
const google::protobuf::RepeatedPtrField<Test>& c {a}; // 2
const google::protobuf::RepeatedPtrField<Test>& d (a); // 3
}
Call (1, 3) works fine, but Call (2) seems to call the copy constructor defined as
template <typename Element>
inline RepeatedPtrField<Element>::RepeatedPtrField(
const RepeatedPtrField& other)
: RepeatedPtrFieldBase() {
MergeFrom(other);
}
Could someone help me understand why Call (2) creates a copy, I seem to be misunderstanding a rule in the initializer list.
Thanks...