So let's say I have a class here called 'Game'. The other method(s), constructor(s) and destructor(s) are completely neglected in my example and are not important or relevant to my question at hand.
// Game.hpp
#pragma once
class Game {
public:
...
bool isRunning() { return mRunning; } // See: mRunning
...
private:
bool mRunning; // Holds if the game is running or not
};
Okay, simple enough right? Now here is where my concern is:
// main.cpp
#include "Game.hpp"
int main(int argc, char* argv[]) {
Game game;
if (game.isRunning()) {
...
}
return EXIT_SUCCESS;
}
What is the difference between that and?:
// main.cpp
#include "Game.hpp"
int main(int argc, char* argv[]) {
Game game;
bool running = game.isRunning();
if (running) {
...
}
return EXIT_SUCCESS;
}
So here is my question: Is there any performance loss/gain at hand? This also applies to bracket scopes I realise. But in terms of performance, does this get optimized? Is it up to the compiler?