F
F
Frip2017-11-21 19:28:51
OOP
Frip, 2017-11-21 19:28:51

How to create a class representative if we do not initially know how many representatives there will be?

Let's say in a program I read some data from a file. And under certain conditions, I need to bring some data set into the class. (for example, we will assume that when declaring a function, I must enter the return type, function name, type and order of parameters in the class).
But, I don't know how many such ads there can be. It can be either 2-3 or 100-1000.
How to make it so that the declaration creates an instance of the class. ?
While writing, it came to mind to make a dynamic array of classes, and after finding the trigger I need, just create a new element of the array.
Or is there a simpler and more concise option?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wexter, 2017-11-21
@Wexter

when declaring a function, I have to put the return type in the class. value, function name, type and order of parameters

this will not work (you can, of course, pervert with templates, but well, nafig).
you should reconsider the chosen project architecture, because you have been taken in the wrong direction at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question