I am using a simple bool pointer class element. Assignment of false or. true behaves differently - see comments in code. I subtract one to check the other below.
I use compiler call g++ -o basic basic.cpp
g++ -o basic basic.cpp
class Test { public: int a; bool* abool; }; int main() { Test t; //t.abool = false; // WORKS //t.abool = true; // ERROR: cannot convert 'bool' to 'bool*' in assignment - expected IMO; // this should work for both values IMO //*(t.abool) = true; // Segmentation fault //*(t.abool) = false; // Segmentation fault cout << t.abool << endl; return 0; }
, false 0. , t.abool = 0;, abool NULL. true 1, , . ( IMO) seg, , undefined.
false
0
t.abool = 0;
abool
NULL
true
1
bool* , -.
bool*
( false ) bool:
bool
bool test; t.abool = 0; // or NULL t.abool = &test;
bool, bool :
*t.abool = true; *t.abool = false;
false works because false is probably treated like 0in g ++
Any literal with a numeric type and a null value can be implicitly converted to a null pointer. boolis a numeric type, and falsehas a value of 0. Nonzero values (for example, true) cannot be implicitly converted to a pointer.
Source: https://habr.com/ru/post/1792497/More articles:python: best way to check conditions and raise exception - pythonWindows Key + [key] shortcut in Winforms application (C #) - c #convert JSON object to JSON tree - jsonConfigure GAE app.yaml app for subdomains - pythonAnonymous type return - c #dump mysql table to CSV (stdout) and then tunnel output to another server - mysqlCapital letter in SimpleDateFormat - javaProblems with brine and encodings - pythonCalculation of the mode for nominal as well as continuous variables in [R] - rhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1792502/how-to-push-to-multiple-git-repositories-using-multiple-accounts-on-the-same-machine&usg=ALkJrhilLPF73LCcYcxWOsj8Prqn87rkwgAll Articles