assert help?

i want to know what does this code mean?
please give me an example of what assert can be replaced with?

1
2
3
4
5
6
7
8
9
10
#include "AssetManager.h"
#include<assert.h>

AssetManager* AssetManager::sInstance = nullptr;

AssetManager::AssetManager()
{
	assert(sInstance == nullptr);//here, what can i replace assert with?
	sInstance = this;
}
assert is a macro with following behavior: if condition is true, program works as usual. If it is false, it immideatly stops program and gives a message about it.
It is a debug feature to help debug programs. It is actually completely deleted in release builds and hence does not incur any cost.

You can replace it with:

1
2
3
4
5
6
7
8
9
10
AssetManager::AssetManager()
{
#ifndef NDEBUG
	if(sInstance != nullptr) {
		std::cerr << "Assertion failed: sInstance == nullptr\n";
		std::abort();
	}
#endif
	sInstance = this;
}
Last edited on
Topic archived. No new replies allowed.