fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. template<typename T>
  5. using SP = std::shared_ptr<T>;
  6.  
  7. class CVPatModel;
  8. typedef SP<CVPatModel> VModel;
  9.  
  10. class CTest
  11. {
  12. public:
  13. void SaveModelToFile( VModel ModelPtr, const char* szFileName );
  14. };
  15.  
  16. class CVPatModel
  17. {
  18. public :
  19. friend void CTest::SaveModelToFile( VModel, const char*);
  20.  
  21. protected :
  22. virtual void Save( const char* szFileName ) { std::cout << "saving to file \"" << szFileName << "\" succeeded!\n"; };
  23. };
  24.  
  25. void CTest::SaveModelToFile( VModel ModelPtr, const char* szFileName )
  26. {
  27. ModelPtr->Save(szFileName);
  28. }
  29.  
  30. int main()
  31. {
  32. VModel vm = std::make_shared<CVPatModel>();
  33. CTest ct;
  34. ct.SaveModelToFile(vm, "bla");
  35. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
saving to file "bla" succeeded!