fork download
  1. #include <string>
  2. #include <iostream>
  3. using FString = std::string;
  4. class APawn
  5. {
  6. FString Name;
  7. public:
  8. APawn() : Name("Pawn"){};
  9. void SetName(FString InName) { Name = InName; }
  10. FString GetName() { return Name; }
  11. };
  12. class ATank : public APawn
  13. {
  14. public:
  15. ATank() { SetName("Tank"); }
  16. void AimAt() { std::cout << "Aiming" << std::endl; }
  17. };
  18.  
  19.  
  20. class ATankPlayerController
  21. {
  22. APawn* Pawn;
  23. public:
  24. ATankPlayerController(APawn* InPawn) { Pawn = InPawn; }
  25. APawn* GetPawn() { return Pawn; }
  26. };
  27.  
  28. int main()
  29. {
  30. ATank Tank;
  31. ATankPlayerController TankPlayerController(&Tank);
  32. std::cout << TankPlayerController.GetPawn()->GetName() << std::endl;
  33. //TankPlayerController.GetPawn()->AimAt(); //error APawn doesn't have AimAt member
  34. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Tank