fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct NameClass
  5. {
  6. NameClass(const std::string & name) : m_name(name) {}
  7.  
  8. std::string getName() const
  9. {
  10. return m_name;
  11. }
  12.  
  13. private:
  14. std::string m_name;
  15. };
  16.  
  17. // Then we can do:
  18.  
  19. struct FinalClass : public NameClass("FinalClass") {};
  20.  
  21. int main()
  22. {
  23. FinalClass fc;
  24. }
  25.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:19:37: error: expected ‘{’ before ‘(’ token
 struct FinalClass : public NameClass("FinalClass") {};
                                     ^
prog.cpp:19:38: error: expected unqualified-id before string constant
 struct FinalClass : public NameClass("FinalClass") {};
                                      ^
prog.cpp:19:38: error: expected ‘)’ before string constant
prog.cpp: In function ‘int main()’:
prog.cpp:23:13: error: aggregate ‘FinalClass fc’ has incomplete type and cannot be defined
  FinalClass fc;
             ^
stdout
Standard output is empty