Jak zrobić odpowiednik zmiennych statycznych bez lączności w zwykłych funkcjach C++ przy użyciu makr preprocesora? Przepraszam za ciągłe wstawianie pytań dzisiaj ale dopiero poznaję C++
#include <iostream>
int test_successes = 0;
int test_failures = 0;
void test_assert(bool expr, std::string_view msg) {
if (expr) {
std::cout << "* test passed: " << msg << std::endl;
++test_successes;
} else {
std::cout << "* test failed: " << msg << std::endl;
++test_failures;
}
}
void test_stats() {
std::cout << "successes: " << test_successes << std::endl;
std::cout << "failures: " << test_failures << std::endl;
}
int main() {
test_assert(2 == 2, "2 == 2");
test_assert(2 < 0 == false, "2 < 0 == false");
test_assert(1 == 3, "1 == 3");
test_stats();
return 0;
}