fork download
  1. #include <stdio.h>
  2. #include <memory.h>
  3.  
  4. using namespace std;
  5.  
  6. int main(void) {
  7. std::shared_ptr<std::string> myPtr = std::make_shared<std::string>("hello");
  8. std::cout << "Refs: " << myPtr.use_count() << std::endl;
  9.  
  10. auto& myPtrRef = myPtr;
  11. std::cout << "Refs: " << myPtrRef.use_count() << std::endl;
  12.  
  13. auto lambda = [myPtrRef] {
  14. std::cout << "Refs: " << myPtrRef.use_count() << std::endl;
  15. };
  16.  
  17. lambda();
  18.  
  19. // your code goes here
  20. return 0;
  21. }
  22.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4:1: error: unknown type name ‘using’
 using namespace std;
 ^~~~~
prog.c:4:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘std’
 using namespace std;
                 ^~~
prog.c: In function ‘main’:
prog.c:7:6: error: expected expression before ‘:’ token
  std::shared_ptr<std::string> myPtr = std::make_shared<std::string>("hello");
      ^
prog.c:8:2: error: duplicate label ‘std’
  std::cout << "Refs: " << myPtr.use_count() << std::endl;
  ^~~
prog.c:7:2: note: previous definition of ‘std’ was here
  std::shared_ptr<std::string> myPtr = std::make_shared<std::string>("hello");
  ^~~
prog.c:8:6: error: expected expression before ‘:’ token
  std::cout << "Refs: " << myPtr.use_count() << std::endl;
      ^
prog.c:10:6: error: expected identifier or ‘(’ before ‘&’ token
  auto& myPtrRef = myPtr;
      ^
prog.c:11:2: error: duplicate label ‘std’
  std::cout << "Refs: " << myPtrRef.use_count() << std::endl;
  ^~~
prog.c:7:2: note: previous definition of ‘std’ was here
  std::shared_ptr<std::string> myPtr = std::make_shared<std::string>("hello");
  ^~~
prog.c:11:6: error: expected expression before ‘:’ token
  std::cout << "Refs: " << myPtrRef.use_count() << std::endl;
      ^
prog.c:13:7: error: type defaults to ‘int’ in declaration of ‘lambda’ [-Werror=implicit-int]
  auto lambda = [myPtrRef] {
       ^~~~~~
prog.c:13:16: error: expected expression before ‘[’ token
  auto lambda = [myPtrRef] {
                ^
prog.c:13:17: error: ‘myPtrRef’ undeclared (first use in this function)
  auto lambda = [myPtrRef] {
                 ^~~~~~~~
prog.c:13:17: note: each undeclared identifier is reported only once for each function it appears in
prog.c:17:2: error: called object ‘lambda’ is not a function or function pointer
  lambda();
  ^~~~~~
prog.c:13:7: note: declared here
  auto lambda = [myPtrRef] {
       ^~~~~~
prog.c:7:2: error: label ‘std’ defined but not used [-Werror=unused-label]
  std::shared_ptr<std::string> myPtr = std::make_shared<std::string>("hello");
  ^~~
cc1: all warnings being treated as errors
stdout
Standard output is empty