By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

Dumb STDLib Deprecation Question

P: n/a
I just upgraded my server to a recent version of redhat, and now old
code no longer compiles. I'm not a C++ coder, but C++ coders who use
my server are now complaining. Here's an example:
#include <iostream>
#include <list>
#include <string>

using namespace std;

template<typename T>
void writeList(const list<T>& alist, const string& separator = " ")
{
list<T>::const_iterator iter;
for(iter = alist.begin(); iter != alist.end(); iter++)
cout << *iter << separator;
cout << endl;
}
int main()
{
return 0;
}

And I get this error:

t1.cpp: In function ‚void writeList(const std::list<T,
std::allocator<_CharT&, const std::string\
&)‚:
t1.cpp:11: error: expected `;' before ‚iter‚
t1.cpp:12: error: ‚iter‚ was not declared in this scope

The user who gave me this example claims that STD lib is somehow not
installed correctly on the new server, but I can't figure out what I
could install additionally. My (completely naive) guess is that his
code is deprecated.

Here's what I can find that might be relevant:

$ cd /usr/lib
$ find . -print | grep libstd
../libstdc++.so.5
../libstdc++-3-libc6.2-2-2.10.0.so
../gcc/x86_64-redhat-linux/4.1.1/libstdc++.a
../gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a
../gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.so
../gcc/x86_64-redhat-linux/4.1.1/libstdc++.so
../libstdc++.so.6
../libstdc++.so.5.0.7
../libstdc++.so.6.0.8
../libstdc++-libc6.2-2.so.3

Thanks in advance!

May 27 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On May 26, 8:47 pm, "JShra...@gmail.com" <JShra...@gmail.comwrote:
I just upgraded my server to a recent version of redhat, and now old
code no longer compiles. I'm not a C++ coder, but C++ coders who use
my server are now complaining. Here's an example:

#include <iostream>
#include <list>
#include <string>

using namespace std;

template<typename T>
void writeList(const list<T>& alist, const string& separator = " ")
{
// the following is a dependant type.
list<T>::const_iterator iter;
// fix:
typename list<T>::const_iterator iter;
for(iter = alist.begin(); iter != alist.end(); iter++)
cout << *iter << separator;
cout << endl;

}

int main()
{
return 0;

}

And I get this error:

t1.cpp: In function ‚void writeList(const std::list<T,
std::allocator<_CharT&, const std::string\
&)‚:
t1.cpp:11: error: expected `;' before ‚iter‚
t1.cpp:12: error: ‚iter‚ was not declared in this scope

The user who gave me this example claims that STD lib is somehow not
installed correctly on the new server, but I can't figure out what I
could install additionally. My (completely naive) guess is that his
code is deprecated.
The code is deprecated but considering how long dependant types have
been ignored, its really not his fault. You might consider suggesting
that he look up the use of 'typename' in the context of dependant
types. Yours is a classic example.
>
Here's what I can find that might be relevant:

$ cd /usr/lib
$ find . -print | grep libstd
./libstdc++.so.5
./libstdc++-3-libc6.2-2-2.10.0.so
./gcc/x86_64-redhat-linux/4.1.1/libstdc++.a
./gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a
./gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.so
./gcc/x86_64-redhat-linux/4.1.1/libstdc++.so
./libstdc++.so.6
./libstdc++.so.5.0.7
./libstdc++.so.6.0.8
./libstdc++-libc6.2-2.so.3

Thanks in advance!

May 27 '07 #2

P: n/a
On May 26, 9:57 pm, Salt_Peter <pj_h...@yahoo.comwrote:
On May 26, 8:47 pm, "JShra...@gmail.com" <JShra...@gmail.comwrote:
I just upgraded my server to a recent version of redhat, and now old
code no longer compiles. I'm not a C++ coder, but C++ coders who use
my server are now complaining. Here's an example:
#include <iostream>
#include <list>
#include <string>
using namespace std;
template<typename T>
void writeList(const list<T>& alist, const string& separator = " ")
{

// the following is a dependant type.
list<T>::const_iterator iter;

// fix:
typename list<T>::const_iterator iter;
for(iter = alist.begin(); iter != alist.end(); iter++)
cout << *iter << separator;
cout << endl;
}
int main()
{
return 0;
}
And I get this error:
t1.cpp: In function ‚void writeList(const std::list<T,
std::allocator<_CharT&, const std::string\
&)‚:
t1.cpp:11: error: expected `;' before ‚iter‚
t1.cpp:12: error: ‚iter‚ was not declared in this scope
The user who gave me this example claims that STD lib is somehow not
installed correctly on the new server, but I can't figure out what I
could install additionally. My (completely naive) guess is that his
code is deprecated.

The code is deprecated but considering how long dependant types have
been ignored, its really not his fault. You might consider suggesting
that he look up the use of 'typename' in the context of dependant
types. Yours is a classic example.
Here's what I can find that might be relevant:
$ cd /usr/lib
$ find . -print | grep libstd
./libstdc++.so.5
./libstdc++-3-libc6.2-2-2.10.0.so
./gcc/x86_64-redhat-linux/4.1.1/libstdc++.a
./gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a
./gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.so
./gcc/x86_64-redhat-linux/4.1.1/libstdc++.so
./libstdc++.so.6
./libstdc++.so.5.0.7
./libstdc++.so.6.0.8
./libstdc++-libc6.2-2.so.3
Thanks in advance!
GOOD ONE. "typename" is used to clarify that const_iterator is a type
defined within class list<T>. I tried
JShrager's code on my fedora 4, the same error produced.

May 27 '07 #3

P: n/a
In article <11*********************@o11g2000prd.googlegroups. com>,
JS******@gmail.com says...
I just upgraded my server to a recent version of redhat, and now old
code no longer compiles. I'm not a C++ coder, but C++ coders who use
my server are now complaining. Here's an example:

#include <iostream>
#include <list>
#include <string>

using namespace std;

template<typename T>
void writeList(const list<T>& alist, const string& separator = " ")
{
list<T>::const_iterator iter;
list<T>::const_iterator is a dependent type -- it depends on a template
parameter (T, in this case). Older compilers incorrectly accepted code
like this, but (most) more recent ones correctly require that you tell
them this is intended to be the name of a type:

typename list<T>::const_iterator iter;
for(iter = alist.begin(); iter != alist.end(); iter++)
cout << *iter << separator;
Just FWIW, your loop appears equivalent to:

std::copy(alist.begin(), alist.end(),
std::ostream_iterator<T>(cout, " "));

--
Later,
Jerry.

The universe is a figment of its own imagination.
May 28 '07 #4

P: n/a
list<T>::const_iterator iter;
>
list<T>::const_iterator is a dependent type -- it depends on a template
parameter (T, in this case). Older compilers incorrectly accepted code
like this, but (most) more recent ones correctly require that you tell
them this is intended to be the name of a type:

typename list<T>::const_iterator iter;
Thanks! (And thanks to the others who replied to this.) I passed on
your adivce to the user who wrote the code, and he has (I think) got
things working now.
for(iter = alist.begin(); iter != alist.end(); iter++)
cout << *iter << separator;

Just FWIW, your loop appears equivalent to:

std::copy(alist.begin(), alist.end(),
std::ostream_iterator<T>(cout, " "));
Ain't my loop, but thanks! :-)
May 29 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.