ImguiSettings::variables& ImSettings = ImguiSettings::getImguiSettings(); variables is a…
- User
ImguiSettings::variables& ImSettings = ImguiSettings::getImguiSettings();
variables is a struct;
if imSettings is how i can check does pointer pointing to null struct or not
- Assistant
You can check if the pointer is pointing to a null struct by comparing it to the null pointer, like this:
if(&ImSettings == nullptr) { // pointer is pointing to null struct } else { // pointer is not pointing to null struct }
- User
but this aint working
- Assistant
I apologize for the confusion. Since
ImSettingsis a reference to theImguiSettings::variablesstruct, you cannot check if it is null using thenullptrkeyword.Instead, you can check if the reference is bound to a valid struct instance by using the address-of operator (
&) to get a pointer to the struct and checking if it is equal tonullptr, like this:ImguiSettings::variables& ImSettings = ImguiSettings::getImguiSettings(); if (&ImSettings == nullptr) { // ImSettings is a null reference } else { // ImSettings is a valid reference to a struct instance }Please let me know if this helps!
- User
i already using this if (&ImSettings == nullptr)
this check passing as valid, even if imSettings struct at NULL
- Assistant
I apologize, the issue might be that
ImSettingsis not actually a pointer, but a reference to theImguiSettings::variablesstruct. Since references cannot be null, the condition&ImSettings == nullptrwill always evaluate to false.Instead, you can check if
ImguiSettings::getImguiSettings()returns a null pointer which will indicate thatImSettingsis also null. Here's an example:ImguiSettings::variables* pImSettings = &ImguiSettings::getImguiSettings(); if (pImSettings == nullptr) { // ImSettings is a null struct } else { // pImSettings is a valid pointer to the ImSettings struct instance }Alternatively, you can modify the
ImguiSettings::getImguiSettings()function to return a nullImguiSettings::variablesstruct instance instead of a null pointer to a struct instance, and then your original checkif (&ImSettings == nullptr)should work as expected. However, this will depend on how the function is implemented and whether it is feasible to modify it.