D
D
dominy2021-08-04 20:05:31
C++ / C#
dominy, 2021-08-04 20:05:31

Is it possible for the compiler to automatically add a variable to a namespace?

Hello I have an empty namespace

namespace Addresses
    {
    }

But I would like to be able to add variables like
uintptr_t Addresses::myAdress = processManager.readMemory(GameAssembly);
that is, so that the compiler itself seems to create a variable in the namespace Addresses
This is not a dynamic allocation of variables, but ordinary variables

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2021-08-04
@Mercury13

This is the only way in any language.

namespace Addresses {
  uintptr_t myAddresses = processManager.xxx;
}

Only in CPP file; in the header
namespace Addresses {
  extern uintptr_t myAddresses;
}

But I don't recommend it for two reasons.
1. Controlling delays during program initialization is a nasty thing. In all languages. For example, in Java ME I asked: do all long operations when something appears on the screen.
2. The second reason is specific to C++. The order of initialization of different modules is not defined. If the manager is in one module and the addresses are in another, the addresses can be initialized with a 50/50 chance when there is no manager yet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question