Portál AbcLinuxu, 10. května 2025 08:57
template <class T> class mvect : public std::vector<T> { public: const std::vector<T>::const_iterator begin() const { return std::vector<T>::begin(); } };Není mi jasné, proč se od překladače dozvím, že:
vect.h:23: error: ISO C++ forbids declaration of 'const_iterator' with no type vect.h:23: error: expected ';' before 'begin' vect.h:29: error: expected `;' before '}' tokenconst_iterator je přeci součást vectoru, ne? Uměl by mi to, prosím, někdo vysvětlit? Díky.
Řešení dotazu:
class Test { public: Test() {} Test(Test&) {} protected: Test(const Test&); } Test getTest() { return Test(); } const Test getTestConst() { return Test(); } void test() { Test t(getTest()); Test t2(getTestConst()); }Mimochodem C++2011 má taky rvalue jenom bez const (Test&&).
const typename std::vector<T>::const_iterator begin() const
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.