template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
/*Compiler says here, ';' shoud occur before ref,and ref is not
declared,but I really don't know what's the problem here*/
out << *ref;
return out;
} 6 1203
"Magcialking дµÀ£º
"
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
/*Compiler says here, ';' shoud occur before ref,and ref is not
declared,but I really don't know what's the problem here*/
out << *ref;
return out;
}
Have you include the header file <list>.
The following code works fine in my compiler.
#include <list>
#include <iostream>
using namespace std;
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
std::cout << *ref << "\n";
return out;
}
int main()
{
list<inta;
a.push_back(1);
cout << a;
return 0;
}
I'm sure I left nothing.
And the code you give doesn't work in my compliler(Mingw)
"mimi дµÀ£º
"
"Magcialking дµÀ£º
"
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
/*Compiler says here, ';' shoud occur before ref,and ref is not
declared,but I really don't know what's the problem here*/
out << *ref;
return out;
}
Have you include the header file <list>.
The following code works fine in my compiler.
#include <list>
#include <iostream>
using namespace std;
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
std::cout << *ref << "\n";
return out;
}
int main()
{
list<inta;
a.push_back(1);
cout << a;
return 0;
}
I'm sure I left nothing.
And the code you give doesn't work in my compliler(Mingw)
"mimi дµÀ£º
"
"Magcialking дµÀ£º
"
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
/*Compiler says here, ';' shoud occur before ref,and ref is not
declared,but I really don't know what's the problem here*/
out << *ref;
return out;
}
Have you include the header file <list>.
The following code works fine in my compiler.
#include <list>
#include <iostream>
using namespace std;
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
std::cout << *ref << "\n";
return out;
}
int main()
{
list<inta;
a.push_back(1);
cout << a;
return 0;
}
Magcialking :
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
/*Compiler says here, ';' shoud occur before ref,and ref is not
declared,but I really don't know what's the problem here*/
out << *ref;
return out;
}
I have compile your code with mingw, and it produce the same
error! The root of the error is that the compiler look
list<T>::const_iterator as a dependent name. So you need to
do
for( typename list<T>::const_iterator ref ...)
and everything is OK!
"Bo Yang дµÀ£º
"
Magcialking :
template<class T>
ostream& operator<< (ostream& out, const list<T>& lst) {
for (list<T>::const_iterator ref = lst.begin(); ref !=
lst.end();ref++)
/*Compiler says here, ';' shoud occur before ref,and ref is not
declared,but I really don't know what's the problem here*/
out << *ref;
return out;
}
I am sorry. Maybe I should uninstall my VC 6.0 immediately.
I have compile your code with mingw, and it produce the same
error! The root of the error is that the compiler look
list<T>::const_iterator as a dependent name. So you need to
do
for( typename list<T>::const_iterator ref ...)
and everything is OK!
Thanx a lot, both of you! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Edward Diener |
last post by:
Is there a way to override the default processing of the assignment operator
for one's own __value types ? I realize I can program my own Assign method,
and provide that for end-users of my class,...
|
by: gorda |
last post by:
Hello,
I am playing around with operator overloading and inheritence,
specifically overloading the + operator in the base class and its
derived class.
The structure is simple: the base class...
|
by: pmatos |
last post by:
Hi all,
I'm overloading operator<< for a lot of classes. The question is about
style. I define in each class header the prototype of the overloading
as a friend. Now, where should I define the...
|
by: John Hardin |
last post by:
All:
The syntax for overloading the "+" and other simple binary math operators
is pretty straightforward, but I can't seem to wrap my brain around the
idea that overloading the "+" operator...
|
by: carlos |
last post by:
Curious:
Why wasnt a primitive exponentiation operator not added to C99?
And, are there requests to do so in the next std revision?
Justification for doing so:
C and C++ are increasingly used...
|
by: Student |
last post by:
Hi All,
I have an assignment for my Programming language project to create a
compiler that takes a C++ file as input and translate it into the C
file. Here I have to take care of inheritance and...
|
by: Steve R. Hastings |
last post by:
While studying iterators and generator expressions, I started wishing I
had some tools for processing the values. I wanted to be able to chain
together a set of functions, sort of like the...
|
by: karthik |
last post by:
The * operator behaves in 2 different ways. It is used as the value at
address operator as well as the multiplication operator. Does this mean
* is overloaded in c?
|
by: brzozo2 |
last post by:
Hello, this program might look abit long, but it's pretty simple and
easy to follow. What it does is read from a file, outputs the contents
to screen, and then writes them to a different file. It...
|
by: Wayne Shu |
last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition).
When I read chapter 11 Operator Overloading, I have two questions.
1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
|
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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: 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: 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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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
| |