fork download
  1. #include <iostream>
  2.  
  3.  
  4. int* alloc( int n )
  5. {
  6. std::cout << "alloc size " << n << std::endl;
  7. return new int[n];
  8. }
  9.  
  10. class A
  11. {
  12. int n;
  13. int *a;
  14. public:
  15. //A(int x): a(new int[n]), n(x)
  16. A(int x): a( alloc(n) ), n(x) d
  17. {
  18. a[n-1] = 111;
  19. }
  20. void showSize()
  21. {
  22. std::cout << a[n - 1] << '\n';
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. A a(10);
  29. a.showSize();
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 2984KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘A::A(int)’:
prog.cpp:13:10: warning: ‘A::a’ will be initialized after [-Wreorder]
prog.cpp:12:9: warning:   ‘int A::n’ [-Wreorder]
prog.cpp:16:5: warning:   when initialized here [-Wreorder]
prog.cpp:16:35: error: expected ‘{’ before ‘d’
prog.cpp: In function ‘int main()’:
prog.cpp:29:7: error: ‘class A’ has no member named ‘showSize’
stdout
Standard output is empty