jeudi 15 novembre 2018

class containing only const member variables

I have a class i need to implement, where all fields must be constant. All the objects created by this class are built on execution, and from that moment on- they are handled by the user. I cannot add/delete any of them (as in, create/delete a new unique object. I may allocate new memory with an identical copy).

I am required to store them in a vector, but the vector cannot hold their pointers(!). what is the best way to construct my program, such that i could access these objects by reference (or in some other way) without creating tons of copies, when they are required to be stored in some other place? (it might be necessary to "link" them to other objects).

I was thinking of a way to use shred-pointers, but as this is my first project in c++, I have no clue how, or if it's even possible.

thanks in advance!

Aucun commentaire:

Enregistrer un commentaire