fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Char{
  5. private:
  6. char cx;
  7. public:
  8. Char(){}
  9. Char(char ctmp):cx(ctmp){}
  10. Char(Char &tmp){ cx=tmp.cx; }
  11. ~Char(){ cx=''; }
  12.  
  13. char getChar(void){ return this->x; }
  14.  
  15. // operator implementations here
  16. Char& operator = (const Char &tmp)
  17. {
  18. cx = tmp.x;
  19. return *this;
  20. }
  21. Char& operator = (char ctmp){
  22. cx = ctmp;
  23. return *this;
  24. }
  25. };
  26.  
  27. int main() {
  28. Char cx('x');
  29. Char cy = 'x';
  30. Char cy = cx;
  31. // your code goes here
  32. return 0;
  33. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:11:25: error: empty character constant
             ~Char(){ cx=''; }
                         ^
prog.cpp: In member function 'char Char::getChar()':
prog.cpp:13:46: error: 'class Char' has no member named 'x'
             char getChar(void){ return this->x; } 
                                              ^
prog.cpp: In member function 'Char& Char::operator=(const Char&)':
prog.cpp:18:23: error: 'const class Char' has no member named 'x'
              cx = tmp.x;
                       ^
prog.cpp: In function 'int main()':
prog.cpp:29:12: error: invalid initialization of non-const reference of type 'Char&' from an rvalue of type 'Char'
  Char cy = 'x';
            ^
prog.cpp:10:13: note:   initializing argument 1 of 'Char::Char(Char&)'
             Char(Char &tmp){ cx=tmp.cx; }
             ^
prog.cpp:9:13: note:   after user-defined conversion: Char::Char(char)
             Char(char ctmp):cx(ctmp){}
             ^
prog.cpp:30:7: error: redeclaration of 'Char cy'
  Char cy = cx;
       ^
prog.cpp:29:7: note: 'Char cy' previously declared here
  Char cy = 'x';
       ^
stdout
Standard output is empty