As you stated that the use of the pointer is unnecessary, I guess you have a use-case where the use would not actually be unnecessary but provides some benefit.
You can use a simple example to verify that most compilers (I tested GCC 5.1, 9.0 and clang 8.0, all x64) produce the exact same code (hence no difference in resource usage) when accessing the object:
- directly
- via pointer
- via reference
#include <iostream>
using namespace std;
class Enemy
{
public:
Enemy() {}
void attack()
{
cout << "attack";
}
};
#define VERSION 1
int main(int argc, char* argv[]) {
Enemy e;
#if VERSION == 1
e.attack();
#elif VERSION == 2
Enemy& e2 = e;
e2.attack();
#else
Enemy* e3 = &e;
e3->attack();
#endif
}
You can easily try different compilers and options with Godbold (includes example above)