Chapter 18 Challenge 2: Stack- why is stack implemented as a struct?

Hi all!

I’m wondering why is Stack implemented as a struct? I’ve implemented Stack as a class thinking because I would need to store the content of the Stack in a data structure that would persist in the memory for a long time, and allows logic to update its internal state. A struct has an implicit copying behaviour (value semantics) and wouldn’t that be a bad candidate for implementing a stack? Please advise, thanks a lot.

image

This topic was automatically closed after 166 days. New replies are no longer allowed.