Guest User

Untitled

a guest
Jul 31st, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. class Mesh {
  5. public:
  6.   static const int a = 1;
  7. };
  8.  
  9. class Light {
  10. public:
  11.   static const int a = 2;
  12. };
  13.  
  14. class Object : public Mesh, public Light {
  15. };
  16.  
  17. template <typename T>
  18. std::shared_ptr<Object> createObject() {
  19.   return std::static_pointer_cast<Object>(std::make_shared<T>());
  20. }
  21.  
  22. int main() {
  23.   auto ptr = createObject<Mesh>();
  24.   std::cout << ptr->Mesh::a;
  25.  
  26.   auto btr = createObject<Light>();
  27.   std::cout << btr->Light::a;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment