RaGa__M
RaGa__M

Reputation: 2571

How to create an array of Message type

The C++ project I have been working on is using Google's protobuf for their data representation and its sort of already created protos file and its been compiled to get away with .cc and .h.Now my question is can I create an array of my message type

class MyMessage : public ::google::protobuf::Message {
...;
....;
}

Because it seems that MyMessage type generated by the Proto compiler doesn't implement any of the array counterparts like [],so will it be ok when i do things like

MyMessage * array = new MyMessage[4]; or using STL is the only choice;

Upvotes: 0

Views: 338

Answers (2)

You can create arrays of any complete type. (You should have a header file with the class definition.)

Upvotes: 0

MyMessage array = new MyMessage[4];

You can't do this as array is a variable of type MyMessage, but new MyMessage[4] gives you a MyMessage* (pointer to an array of MyMessages).

You could do either

MyMessage array[4];

or

MyMessage *array = new MyMessage[4];

Upvotes: 2

Related Questions