fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct A
  6. {
  7. bool bValid;
  8. bool isValid() { return bValid; }
  9. A(bool b = false) : bValid(b) {}
  10. };
  11.  
  12. A foo()
  13. {
  14. return true;
  15. }
  16.  
  17. int main() {
  18. // your code goes here
  19. //if (auto a = foo()) //!!!!!!!!! как тут вызвать A::isValid()?
  20. if ((auto a = foo()).isValid()) // а так не работает
  21. {
  22. cout<<"a = "<<a<<"\n";
  23. }
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:7: error: expected primary-expression before ‘auto’
  if ((auto a = foo()).isValid()) // а так не работает
       ^~~~
prog.cpp:20:7: error: expected ‘)’ before ‘auto’
prog.cpp:24:2: error: expected ‘)’ before ‘return’
  return 0;
  ^~~~~~
stdout
Standard output is empty