Hi,
I have a small problem with creating a container class using std::list as
the actual container. Here is what should work:
template <typename T>
class Container
{
std::list<T> mList;
typename std::list<T>::const_iterator cIt;
public:
bool isValid() const
{
for( cIt it = mList.begin(); it != mList.end() ; ++it)
dosomething();
}
};
Now my compiler (gcc4) doesn't like the part "cIt it = ", he tells me that
he'd like to have a ";" after cIt:
datalist.cpp:27: error: expected `;' before 'it'
What am I doing wrong here?
Andreas 8 12365
"Andreas Pakulat" <ap***@gmx.de> wrote in message
news:43******@news.uni-rostock.de Hi,
I have a small problem with creating a container class using std::list as the actual container. Here is what should work:
template <typename T> class Container { std::list<T> mList; typename std::list<T>::const_iterator cIt;
Change this to
typedef typename std::list<T>::const_iterator cIt;
public: bool isValid() const { for( cIt it = mList.begin(); it != mList.end() ; ++it) dosomething(); } };
Now my compiler (gcc4) doesn't like the part "cIt it = ", he tells me that he'd like to have a ";" after cIt:
datalist.cpp:27: error: expected `;' before 'it'
What am I doing wrong here?
See above. You also haven't defined dosomething() or given isValid a return
value, but I presume that it is done in your real code.
--
John Carson
Andreas Pakulat wrote: I have a small problem with creating a container class using std::list as the actual container. Here is what should work:
template <typename T> class Container { std::list<T> mList; typename std::list<T>::const_iterator cIt;
You lost 'typedef':
typedef typename std::list<T>::const_iterator cIt;
public: bool isValid() const { for( cIt it = mList.begin(); it != mList.end() ; ++it) dosomething();
You lost the 'return' statement here.
} };
Now my compiler (gcc4) doesn't like the part "cIt it = ", he tells me that he'd like to have a ";" after cIt:
datalist.cpp:27: error: expected `;' before 'it'
What am I doing wrong here?
Not much, but enough.
V
John Carson wrote: "Andreas Pakulat" <ap***@gmx.de> wrote in message news:43******@news.uni-rostock.de Hi,
I have a small problem with creating a container class using std::list as the actual container. Here is what should work:
template <typename T> class Container { std::list<T> mList; typename std::list<T>::const_iterator cIt; Change this to
typedef typename std::list<T>::const_iterator cIt;
Ok, but why does the following not work?
for ( std::list<T>::const_iterator it = mList.begin(); it != mList.end();
++it)
See above. You also haven't defined dosomething() or given isValid a return value, but I presume that it is done in your real code.
Right, I was just too lazy as neither the return nor dosomething have
anything to do with my problem.
Andreas
"Andreas Pakulat" <ap***@gmx.de> wrote in message
news:43******@news.uni-rostock.de... John Carson wrote:
"Andreas Pakulat" <ap***@gmx.de> wrote in message news:43******@news.uni-rostock.de Hi,
I have a small problem with creating a container class using std::list as the actual container. Here is what should work:
template <typename T> class Container { std::list<T> mList; typename std::list<T>::const_iterator cIt;
Change this to
typedef typename std::list<T>::const_iterator cIt;
Ok, but why does the following not work?
for ( std::list<T>::const_iterator it = mList.begin(); it != mList.end();
^
+---- typename
For same reasons as the typedef.
Jeff Flinn
Andreas Pakulat wrote: John Carson wrote:"Andreas Pakulat" <ap***@gmx.de> wrote in message news:43******@news.uni-rostock.de
Hi,
I have a small problem with creating a container class using std::list as the actual container. Here is what should work:
template <typename T> class Container { std::list<T> mList; typename std::list<T>::const_iterator cIt; Change this to
typedef typename std::list<T>::const_iterator cIt;
Ok, but why does the following not work?
for ( std::list<T>::const_iterator it = mList.begin(); it != mList.end(); ++it)
For the same reason you have to use 'typename' in the 'cIt' declaration.
Without 'cIt', you would need to write
for ( typename std::list<T>::const_iterator ...
[...]
V
Victor Bazarov wrote: Andreas Pakulat wrote: John Carson wrote:"Andreas Pakulat" <ap***@gmx.de> wrote in message news:43******@news.uni-rostock.de
Hi,
I have a small problem with creating a container class using std::list as the actual container. Here is what should work:
template <typename T> class Container { std::list<T> mList; typename std::list<T>::const_iterator cIt;
Change this to
typedef typename std::list<T>::const_iterator cIt;
Ok, but why does the following not work?
for ( std::list<T>::const_iterator it = mList.begin(); it != mList.end(); ++it)
For the same reason you have to use 'typename' in the 'cIt' declaration. Without 'cIt', you would need to write
for ( typename std::list<T>::const_iterator ...
Ok, thanks and be assured I am looking for a C++-book on templates
(unfortunately my c++ book has only a very short chapter).
Andreas
On Fri, 04 Nov 2005 17:20:54 +0100, Andreas Pakulat wrote: Victor Bazarov wrote:[..]
for ( typename std::list<T>::const_iterator ...
Ok, thanks and be assured I am looking for a C++-book on templates (unfortunately my c++ book has only a very short chapter).
You could start by reading the FAQ...
V
"Andreas Pakulat" <ap***@gmx.de> wrote in message
news:43******@news.uni-rostock.de Ok, thanks and be assured I am looking for a C++-book on templates (unfortunately my c++ book has only a very short chapter). http://www.vandevoorde.com/C++Templates/
--
John Carson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: NKOBAYE027 |
last post by:
FIRST POST
Hi All: I'm trying to write a simple specialization before moving on to
something a bit more complex - always a good idea in my case, at least. :o)
I'm trying to adapt the example...
|
by: rg |
last post by:
Hi all,
I was wondering if anyone had dealt with a similar problem. I need to use a
template function as the parameter for a particular function (also template
function).
The program compiles...
|
by: darkstorm |
last post by:
Please check this program...When I compiles it in VC.net, it gives the
following error:
===============
Common\Lib\PList.h(115): error C2440: '=' : cannot convert from
'ListNode *' to...
|
by: cyberdave |
last post by:
Someone please help me!
I have a template class like this:
--------------------------------------------------
template<typename T>
class List
{
public:
|
by: Joe Carner via .NET 247 |
last post by:
First time posting, thanks in advance for any help you can give me.
Basically I am trying to a class that i want to be able to access the private data members of another class, both of which i...
|
by: chriscorbell |
last post by:
I'm curious about what appears to be a restriction on using an STL
container inside a user-defined template, esp. using an iterator to
such a container. It's not clear to me if this is a general...
|
by: flamexx7 |
last post by:
Can anybody tell me what is wrong with declaration of pointer p ?
template<class Tclass Stack {
struct Link {
T* data;
Link* next;
Link(T* dat, Link* nxt)
: data(dat), next(nxt) {}
}* head;...
|
by: Fab |
last post by:
All,
I need your help understanding why the following code does *NOT*
compile with G++ (tested with gcc 3.x and 4.1.x):
---------------------------------------------------------------------...
|
by: jubelbrus |
last post by:
Hi
I'm trying to do the following.
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
class {
|
by: Adrian |
last post by:
In the following code example I am trying to create a generic interface for a bunch of objects. Each concrete type is stored in its own container and the a container of pointer's to base is used so I...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |