473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Aug 10 '06 #1
1 1497
ke***********@hotmail.com wrote:
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
Aug 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: murali | last post by:
Hi, I get tollowing linking errors Main.cpp:30 undefined reference to Matrix<int>::Matrix(int,int) whats that '' and what might be the problem ?? line 30 of main:...
7
by: fabio de francesco | last post by:
Hello, I'm just joking with the Subject, but I really don't know how to make a synthesis of two questions about some code I'm trying to write. In the following I post this little code, with...
4
by: Thomi Richards | last post by:
Hi, I'm trying to create a simple stack class using C++ and templates. Everything works well and good if I amke the class totally inline. However, as soon as I try to seperate the class into a...
1
by: Generic Usenet Account | last post by:
I am "plugging in" a class type into an STL map definition and I am getting linker errors unless all my class definitions are defined in the header file, as opposed to a separate source file. This...
12
by: Fabio De Francesco | last post by:
Hello. I can't understand why I can't compile the following simple code, where I think I have applied all the needed rules for templates that are declared and defined in different files (*.h and...
1
by: Rebecca Hoffmann | last post by:
Hi, I have a serious problem while compiling a small project (a part of the Modular Flow Scheduling Middleware: ex1): There are 3 linker errors, all from symbols that point to templates: --...
3
by: Chris B | last post by:
Im trying out VS.NET 2003 by trying to make my own single linked list library. Im trying to use templates but keep getting LNK2019 errors. Right now I slimmed down my project to just the main.cpp,...
10
by: Joe Van Dyk | last post by:
Hi, Why are compiler errors in C++ generally so friggen ugly and verbose? To keep this on topic, does the standard guarantee this? :) Thanks, Joe
0
by: C.W.Holeman II | last post by:
I am using Firefox for details see: http://emle.sourceforge.net/emle020100/ng20070620_context.html http://emle.sourceforge.net/emle020100/ng20070621_emle_lab_011.xsd and...
1
by: Giuseppe.G. | last post by:
Hello Paavo, thanks for your kind reply. You may certainly be right, since it appears the author last worked on this toolkit back in 2006. I wish I knew more about templates, unfortunately I'm just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.