Portál AbcLinuxu, 8. listopadu 2025 19:49
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&&).
Jinak vám tam chybí typename, protože jde o typ definovaný v šabloně:
const typename std::vector<T>::const_iterator begin() const
Pro můj účel to funguje, dělá to přesně to, co jsem chtěl - tj. můžu snadno sledovat, kdy se ta metoda volá.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.