[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Template Defintitions
From: |
Ulrich Eckhardt |
Subject: |
Re: Template Defintitions |
Date: |
Mon, 16 Oct 2006 14:24:17 +0200 |
User-agent: |
KNode/0.10.4 |
mrobinson@virtc.com wrote:
> namespace FAII
> {
> template <class T>
> class ArrayDataType : public DataType
> {
> public:
> typedef std::vector<T*> ArrayVector;
Note that ArrayVector is a "dependant type".
> ArrayDataType(const FAIIstring& elementName);
Just as a side notice: this should be 'explicit'.
> };
^ right&necessary
> };
^ wrong (probably ignored by the compiler nonetheless)
> #include "ArrayDataType.h"
>
> template <class T>
> FAII::ArrayDataType<T>::~ArrayDataType()
> {
> ArrayVector::const_iterator itr;
Okay, here's the problem: since 'ArrayVector' is a dependant type, you need
to use 'typename' here:
typename ArrayVector::const_iterator itr;
> for (itr = m_array.begin(); itr != m_array.end(); itr++)
> delete (*itr);
> m_array.clear();
> }
BTW: I think you would be better off using a ready-made container like e.g.
those in Boost. Also, prefer putting indices/iterators into the loop's
header and use prefix increment rather than postfix, but that's just
common C++ sanity.
Uli
--
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/