user1996608
user1996608

Reputation:

Dynamic changes to Data types in c++?

I am developing a Client-Server prototype with protocol Buffers. I have two main requirements to see how efficient Protocol Buffers is and the requirements are following.

Do you have any idea how c++ deals with Run-time changes ?

Upvotes: 1

Views: 90

Answers (2)

barak manos
barak manos

Reputation: 30136

This answer contains only general guidelines, and I will probably get down-voted on it:

  1. Use a linked-list (or any other data structure that can be used as FIFO), instead of an array.

  2. Define a generic class called DataType, with a set of interface routines common to all your different data types.

  3. For every data type you have, define a specific class which inherits from class DataType.

  4. In each node in the linked list, store a pointer to a DataType instance; whenever you add a new entry, create a new instance of one of your data-type classes, and set the DataType pointer of the new entry to point to that instance.

  5. Make sure that the destructor in class DataType is virtual, i.e., virtual ~DataType().

P.S.: the guidelines above are under the assumption that you have a finite number of different data types defined in advanced.

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 993075

Do you have any idea how c++ deals with Run-time changes ?

It doesn't. C++ does not have any facility to change the definition of a struct or class at runtime.

However, depending on your needs, you can use existing C++ data structures such as std::map to implement your own data container whose members can change at runtime.

Upvotes: 1

Related Questions