Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 10th, 2006, 11:05 AM
kelvin.koogan@hotmail.com
Guest
 
Posts: n/a
Default Errors with templates

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

  #2  
Old August 10th, 2006, 11:55 AM
Kai-Uwe Bux
Guest
 
Posts: n/a
Default Re: Errors with templates

kelvin.koogan@hotmail.com wrote:
Quote:
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.
Quote:
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++ )

Quote:
// 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles