Errors with templates

K

kelvin.koogan

Does anyone know what is wrong with the following code and how to fix
it? See gnu 3.4.3 errors below. (This code works fine with VS 2003 and
earlier versions of gnu).

I can get rid of some errors with:
TLength counter = std::vector<TData>::size();
Is that the right thing to do?

However I really don't know what to do about the error produced by:
std::vector<TData>::iterator it

Thanks.

template <typename TLength, class TData>
class CVariableLengthArray : public CDataType, public
std::vector<TData>
{
public:
explicit CVariableLengthArray (size_t n=0) : std::vector<TData>(n)
{}

private:
virtual void Write (CRawMemory & memory)
{
TLength counter = size();
// LINE 192
memory << counter;

for( std::vector<TData>::iterator it = begin(); it != end(); it++ )
// LINE 195
memory << (*it);
}
};

.../../DataTypes.h: In member function `virtual void
CVariableLengthArray<TLength, TData>::Write(CRawMemory&)':
.../../DataTypes.h:192: error: there are no arguments to `size' that
depend on a template parameter, so a declaration of `size' must be
available
.../../DataTypes.h:192: error: (if you use `-fpermissive', G++ will
accept your code, but allowing the use of an undeclared name is
deprecated)
.../../DataTypes.h:195: error: expected `;' before "it"
.../../DataTypes.h:195: error: `it' undeclared (first use this function)
.../../DataTypes.h:195: error: (Each undeclared identifier is reported
only once for each function it appears in.)
.../../DataTypes.h:195: error: there are no arguments to `end' that
depend on a template parameter, so a declaration of `end' must be
available
 
K

Kai-Uwe Bux

Does anyone know what is wrong with the following code and how to fix
it? See gnu 3.4.3 errors below. (This code works fine with VS 2003 and
earlier versions of gnu).

I can get rid of some errors with:
TLength counter = std::vector<TData>::size();
Is that the right thing to do?
Yes.

However I really don't know what to do about the error produced by:
std::vector<TData>::iterator it

Thanks.

template <typename TLength, class TData>
class CVariableLengthArray : public CDataType, public
std::vector<TData>
{
public:
explicit CVariableLengthArray (size_t n=0) : std::vector<TData>(n)
{}

private:
virtual void Write (CRawMemory & memory)
{
TLength counter = size();
// LINE 192
memory << counter;

for( std::vector<TData>::iterator it = begin(); it != end(); it++ )

try

for( typename std::vector<TData>::iterator it = begin(); it != end();
it++ )

// LINE 195
memory << (*it);
}
};

[snip]

BTW.: without knowing more details, it is somewhat hard to be sure; however,
there are only a few cases (actually I know only one case) where inheriting
publicly from std::vector is a good thing to do -- and your class does not
look like one of them. Search the archives of this group and its moderated
twin for discussions of this topic. Very likely, you will find that your
design is asking for trouble.


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top