Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
In your example, there are classes without data at all, so there is no difference between the first and second options. The third will allocate memory for the object not on the stack, but on the heap - therefore, the allocation and work with the object will usually take longer.
If there were data in the object , then the first option would be the fastest, because it would not initialize anything, unlike the others.
If the object also had a constructor , then the first and second variants would be identical.
The third option always initializes the object and allocates memory, so it will be slower.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question