Similar to this question, but different enough that I don't think this is a duplicate:
C ++ function call before initializing base class in initialization list
I have this constructor:
EditorGrid::EditorGrid(int width, int height) : Grid(width , //workingWidth height , //workingHeight (SettingsApp::getInstance(0)->iconSize + SettingsApp::getInstance(0)->iconSpace ) , //pitchWidth (SettingsApp::getInstance(0)->iconSize + SettingsApp::getInstance(0)->iconSpace + SettingsApp::getInstance(0)->iconLabel) //pitchHeight ) { //EditorGrid-specific setup }
It works, but it seems ugly to call SettingsApp::getInstance(0) so many times when I know that it will return the same every time. Can I call it once and just reuse this value in this context?
(in this case, a pointer to the SettingsApp object)
(The reason it is structured is because different Grid children have different equations for pitchWidth and pitchHeight , and I want the singleton idea to implicitly use the same object everywhere, without passing it at all.)
source share