fork download
  1. #include <vector>
  2.  
  3. struct Test
  4. {
  5. int MyField = 0;
  6. };
  7.  
  8. template<class Container, typename T>
  9. class CContainerP
  10. {
  11. Container m_c;
  12. public:
  13. template<typename TpRefValue, class F>
  14. bool findElement(TpRefValue &refValue, F f, const T* &elem) const
  15. {
  16. for (auto it = m_c.begin(); it != m_c.end(); ++it)
  17. {
  18. auto element = *it;
  19. if (element->*f == refValue)
  20. {
  21. elem = element;
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. };
  28.  
  29. int main()
  30. {
  31. CContainerP<std::vector<Test*>, Test> o;
  32. int iRef = 0;
  33. const Test *p = nullptr;
  34. bool bFound = o.findElement(iRef, &Test::MyField, p);// не компилируется
  35. return 0;
  36. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty