environment.cc 838 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // { dg-do run }
  2. extern "C" int printf(const char *, ...);
  3. class Environment {
  4. public:
  5. virtual ~Environment();
  6. // Static factory method that returns the implementation that provide the
  7. // appropriate platform-specific instance.
  8. static Environment* Create();
  9. // Gets an environment variable's value and stores it in |result|.
  10. // Returns false if the key is unset.
  11. virtual bool GetVar(const char* variable_name, char* result) = 0;
  12. };
  13. class EnvironmentImpl : public Environment {
  14. public:
  15. virtual bool GetVar(const char* variable_name, char* result) {
  16. return true;
  17. }
  18. };
  19. Environment::~Environment() {}
  20. // static
  21. Environment* Environment::Create() {
  22. return new EnvironmentImpl();
  23. }
  24. int main()
  25. {
  26. char * null = 0;
  27. Environment * env = Environment::Create();
  28. env->GetVar(0, null);
  29. printf("%p\n", env);
  30. }