在使用 Repeated 类型 链表结构 使用add_foo() 以后,要注意clear_foo() 释放内存空间,最好的办法是在该链表类的析构方法中执行 this->clear_foo();
Repeated Embedded Message Fields
Given the message type:
message Bar {}
For this field definitions:
repeated Bar foo = 1;
The compiler will generate the following accessor methods:
-
int foo_size() const
: Returns the number of elements currently in the field. -
const Bar& foo(int index) const
: Returns the element at the given zero-based index. -
Bar* mutable_foo(int index)
: Returns a mutable pointer to theBar
object that stores the value of the element at the given zero-based index. The pointer is invalidated by a call toClear()
orclear_foo()
, or by manipulating the underlyingRepeatedPtrField
in a way that would remove this element. -
Bar* add_foo()
: Adds a new element and returns a pointer to it. The returnedBar
will have none of its fields set (i.e. it will be identical to a newly-allocatedBar
). The pointer is invalidated by a call toClear()
orclear_foo()
, or by manipulating the underlyingRepeatedPtrField
in a way that would remove this element. -
void clear_foo()
: Removes all elements from the field. After calling this,foo_size()
will return zero. -
const RepeatedPtrField<Bar>& foo() const
: Returns the underlyingRepeatedPtrField
that stores the field's elements. This container class provides STL-like iterators and other methods. -
RepeatedPtrField<Bar>*
mutable_foo(): Returns a mutable pointer to the underlyingRepeatedPtrField
that stores the field's elements. This container class provides STL-like iterators and other methods.