Is it worth creating a class for only one object?

Hello,

I often see libraries with classes, then in practice most of the time I only need one object of this class. Is it worth modifying these libraries so that they no longer need to create objects? Or the compiler is smart enough and do the job for me?

Thanks

No. A class even with a single instance is a good way of keeping every thing together. Some classes never have any instances but are a way of keeping a group of related thing together.

Mark

If you don't have any virtual methods I think the overhead of having a single instance would be small.

An alternative is to use a namespace if you want everything to be "under" some name.

Ok, thanks for your advices :slight_smile: