fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Console
  5. {
  6. private:
  7. static void title_set(const std::string& title)
  8. {
  9. SetConsoleTitle(title.c_str());
  10. }
  11.  
  12. static std::string title_get()
  13. {
  14. char title[MAX_PATH];
  15. GetConsoleTitle(title, MAX_PATH);
  16. return title;
  17. }
  18.  
  19. public:
  20. //all these are valid:
  21. /*1)*/static_property(std::string, Title, title_set, title_get);
  22. //2) static_property(std::string, Title, title_get, title_set);
  23. //3) static_property(std::string, Title, title_set);
  24. //4) static_property(std::string, Title, title_get);
  25.  
  26. // If 4) is used for example, Title = "hello world" would throw a static_assert.
  27. // saying the property is read only.
  28. };
  29.  
  30. // The sizeof(Console::Title) is 1
  31.  
  32. int main()
  33. {
  34. Console::Title = "Hello World";
  35. std::string title = Console::Title;
  36.  
  37. // your code goes here
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:21:40: error: 'Title' has not been declared
     /*1)*/static_property(std::string, Title, title_set, title_get);
                                        ^
prog.cpp:21:47: error: 'title_set' is not a type
     /*1)*/static_property(std::string, Title, title_set, title_get);
                                               ^
prog.cpp:21:58: error: 'title_get' is not a type
     /*1)*/static_property(std::string, Title, title_set, title_get);
                                                          ^
prog.cpp:21:67: error: ISO C++ forbids declaration of 'static_property' with no type [-fpermissive]
     /*1)*/static_property(std::string, Title, title_set, title_get);
                                                                   ^
prog.cpp: In static member function 'static void Console::title_set(const string&)':
prog.cpp:9:32: error: 'SetConsoleTitle' was not declared in this scope
   SetConsoleTitle(title.c_str());
                                ^
prog.cpp: In static member function 'static std::string Console::title_get()':
prog.cpp:14:14: error: 'MAX_PATH' was not declared in this scope
   char title[MAX_PATH];
              ^
prog.cpp:15:19: error: 'title' was not declared in this scope
   GetConsoleTitle(title, MAX_PATH);
                   ^
prog.cpp:15:34: error: 'GetConsoleTitle' was not declared in this scope
   GetConsoleTitle(title, MAX_PATH);
                                  ^
prog.cpp: In function 'int main()':
prog.cpp:34:2: error: 'Title' is not a member of 'Console'
  Console::Title = "Hello World";
  ^
prog.cpp:35:22: error: 'Title' is not a member of 'Console'
  std::string title = Console::Title;
                      ^
stdout
Standard output is empty