fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Person
  5. {
  6. std::string firstName;
  7. std::string lastName;
  8. int id;
  9. public:
  10. Person(std::string first, std::string last, int num);
  11. ~Person(void);
  12. };
  13.  
  14. Person::Person(std::string first, std::string last, int num)
  15. :firstName(first), lastName(last), id(num)
  16. {
  17. std::cout<<"Constructing person: "<<
  18. firstName<<" "<<lastName<<" "<<id<<std::endl;
  19. }
  20.  
  21. Person::~Person(void)
  22. {
  23. std::cout<<"Desstructing person: "<<
  24. firstName<<" "<<lastName<<" "<<id<<std::endl;
  25. }
  26.  
  27.  
  28. int main() {
  29. // your code goes here
  30. Person p1("Anurag", "Jain", 1);
  31. Person p2(){std::cout<<"hello\n";};
  32. return 0;
  33. }
Compilation error #stdin compilation error #stdout 0s 3432KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:31:13: error: a function-definition is not allowed here before ‘{’ token
  Person p2(){std::cout<<"hello\n";};
             ^
stdout
Standard output is empty