TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24471 19
Should I store a helper object as a class member or create it locally inside a method in C++?

I have a base Layer class that I expose from a DLL. My application loads this DLL and then defines its own layer types that inherit from this base class. Here is the simplified definition:

class Layer
{
public:
virtual ~Layer() {};
virtual void OnUpdate() {};
virtual void OnEvent() {};
virtual void OnRender() {};
Rescaler rescaler;
};

All other layer types in my application inherit from this class.


The Rescaler object is responsible for scaling all drawing coordinates.
The user can set a custom window resolution for the application, and Rescaler converts the logical coordinates used by the layer into the final resolution used for rendering.

This scaling is only needed during the OnRender() step and it is not needed outside rendering.

Given that:

1. the base Layer class is part of a DLL,
2. application-specific layers inherit from it,
3. Rescaler is only used to scale rendering coordinates based on user-selected resolution,

my question is:

Should Rescaler remain a member of the base Layer class, be moved only into derived classes that actually need coordinate scaling, or simply be created locally inside OnRender()?

What is the recommended design in this scenario?

https://redd.it/1pk7x36
@r_cpp
Reddit From the cpp community on Reddit: [ Removed by moderator ] Posted by b0nbashagg - 7 votes and 8 comments
More from @r_cpp
  1. Oct 11, 2026wxWidgets 3.2.12 and 3.3.4 Released https://wxwidgets.org/news/2026/10/wxwidgets-3.2.12-an…
  2. Oct 11, 2026VKRT NES Remaster — an open-source C++20 NES emulator with an observation-driven remasteri…
  3. Oct 11, 2026Right way to test async code https://redd.it/1x2wqgz @r_cpp
  4. Oct 10, 2026Yantra: an LALR(1) parser generator for C++23 Yantra: an LALR(1) parser generator for C++2…
  5. Oct 10, 2026Opting in, and back out again https://dryperspective.github.io/posts/opting-in/ https://re…
  6. Oct 10, 2026I’m Building Bursztyn OS a Polish Operating System From Scratch I’m building Bursztyn OS,…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →