fork download
  1. #include<iostream>
  2.  
  3.  
  4. class date{
  5. private:
  6. int A;
  7. int B;
  8. int C = A+B;
  9.  
  10. public:
  11. date(int,int);
  12.  
  13. bool setA(int a){
  14. A = a;
  15. return true;
  16. }
  17.  
  18. int getC(){
  19. return C;
  20. }
  21.  
  22. };
  23. void date::date(int a,int b):A(a),B(b),C(a+b){}
  24.  
  25.  
  26. int main(){
  27. date* hoge = new hoge(1,2);
  28.  
  29. hoge->setA(5);
  30.  
  31. std::cout << hoge->getC() ;
  32. // なんで3なの!!!!!!!!!!!!
  33.  
  34. return 0;
  35.  
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:23:28: error: return type specification for constructor invalid
 void date::date(int a,int b):A(a),B(b),C(a+b){}
                            ^
prog.cpp: In function ‘int main()’:
prog.cpp:27:19: error: expected type-specifier before ‘hoge’
  date* hoge = new hoge(1,2);
                   ^~~~
stdout
Standard output is empty