fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <memory>
  5.  
  6. int i=0;
  7.  
  8. struct B {
  9. int p = 1;
  10. };
  11.  
  12. struct A : public B
  13. {
  14. A()
  15. {
  16. array_ = { std::shared_ptr< B >( new B ) };
  17. }
  18.  
  19. std::vector< std::shared_ptr< B > >::iterator begin()
  20. {
  21. return array_.begin();
  22. }
  23.  
  24. std::vector< std::shared_ptr< B > >::const_iterator begin() const
  25. {
  26. return array_.begin();
  27. }
  28.  
  29. std::vector< std::shared_ptr< B > >::iterator end ()
  30. {
  31. return array_.end();
  32. }
  33.  
  34. std::vector< std::shared_ptr< B > >::const_iterator end () const
  35. {
  36. return array_.end();
  37. }
  38.  
  39. std::vector< std::shared_ptr< B > > array_;
  40. };
  41.  
  42. int main()
  43. {
  44. B* a = new B();
  45. for( auto it : static_cast< A* >( a ) )
  46. {
  47. std::cout << it->p << std::endl;
  48. }
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:45:41: error: no matching function for call to ‘begin(A*&)’
     for( auto it : static_cast< A* >( a ) )
                                         ^
prog.cpp:45:41: note: candidates are:
In file included from /usr/include/c++/4.8/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.8/string:52,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
     begin(initializer_list<_Tp> __ils) noexcept
     ^
/usr/include/c++/4.8/initializer_list:89:5: note:   template argument deduction/substitution failed:
prog.cpp:45:41: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘A*’
     for( auto it : static_cast< A* >( a ) )
                                         ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:87:5: note: template<class _Tp, unsigned int _Nm> _Tp* std::begin(_Tp (&)[_Nm])
     begin(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/4.8/bits/range_access.h:87:5: note:   template argument deduction/substitution failed:
prog.cpp:45:41: note:   mismatched types ‘_Tp [_Nm]’ and ‘A*’
     for( auto it : static_cast< A* >( a ) )
                                         ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:58:5: note: template<class _Container> decltype (__cont.begin()) std::begin(const _Container&)
     begin(const _Container& __cont) -> decltype(__cont.begin())
     ^
/usr/include/c++/4.8/bits/range_access.h:58:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.begin()) std::begin(const _Container&) [with _Container = A*]’:
prog.cpp:45:41:   required from here
/usr/include/c++/4.8/bits/range_access.h:58:5: error: request for member ‘begin’ in ‘__cont’, which is of pointer type ‘A* const’ (maybe you meant to use ‘->’ ?)
/usr/include/c++/4.8/bits/range_access.h:48:5: note: template<class _Container> decltype (__cont.begin()) std::begin(_Container&)
     begin(_Container& __cont) -> decltype(__cont.begin())
     ^
/usr/include/c++/4.8/bits/range_access.h:48:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container = A*]’:
prog.cpp:45:41:   required from here
/usr/include/c++/4.8/bits/range_access.h:48:5: error: request for member ‘begin’ in ‘__cont’, which is of pointer type ‘A*’ (maybe you meant to use ‘->’ ?)
prog.cpp:45:41: error: no matching function for call to ‘end(A*&)’
     for( auto it : static_cast< A* >( a ) )
                                         ^
prog.cpp:45:41: note: candidates are:
In file included from /usr/include/c++/4.8/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.8/string:52,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/initializer_list:99:5: note: template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^
/usr/include/c++/4.8/initializer_list:99:5: note:   template argument deduction/substitution failed:
prog.cpp:45:41: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘A*’
     for( auto it : static_cast< A* >( a ) )
                                         ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:97:5: note: template<class _Tp, unsigned int _Nm> _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/4.8/bits/range_access.h:97:5: note:   template argument deduction/substitution failed:
prog.cpp:45:41: note:   mismatched types ‘_Tp [_Nm]’ and ‘A*’
     for( auto it : static_cast< A* >( a ) )
                                         ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:78:5: note: template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^
/usr/include/c++/4.8/bits/range_access.h:78:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.end()) std::end(const _Container&) [with _Container = A*]’:
prog.cpp:45:41:   required from here
/usr/include/c++/4.8/bits/range_access.h:78:5: error: request for member ‘end’ in ‘__cont’, which is of pointer type ‘A* const’ (maybe you meant to use ‘->’ ?)
/usr/include/c++/4.8/bits/range_access.h:68:5: note: template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^
/usr/include/c++/4.8/bits/range_access.h:68:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.end()) std::end(_Container&) [with _Container = A*]’:
prog.cpp:45:41:   required from here
/usr/include/c++/4.8/bits/range_access.h:68:5: error: request for member ‘end’ in ‘__cont’, which is of pointer type ‘A*’ (maybe you meant to use ‘->’ ?)
stdout
Standard output is empty