A
aaragon
I am trying to create a vector of type T and everything goes fine until
I try to iterate over it. For some reason, the compiler gives me an
error when I declare
std::vector<T>::iterator iter;
Any ideas why is tihs happening? The code is as follows:
template <class T>
struct StdVectorStorage
{
std::vector<T>* _storage;
void create(size_t p,size_t l)
{
_storage = new std::vector<T>(p);
std::vector<T>::iterator iter;
}
~StdVectorStorage()
{
}
};
g++ -c -o main.o main.cxx -pg -O2 -Wall -Wno-sign-compare
gaPolicies.h: In member function 'void
StdVectorStorage<T>::create(size_t, size_t)':
gaPolicies.h:37: error: expected `;' before 'iter'
gaPopulation.h: In member function 'void Population<Individual,
StoragePolicy>::initialize(gaParameters*) [with Individual =
Individual<Chromosome<BoostBitsetStorage>, HeapStorage>, StoragePolicy
= StdVectorStorage]':
gaSimpleGA.h:152: instantiated from 'void gaSimple<Population,
SelectionPolicy>::initialize(int, char**) [with Population =
Population<Individual<Chromosome<BoostBitsetStorage>, HeapStorage>,
StdVectorStorage>, SelectionPolicy = ProportionateSelector]'
main.cxx:16: instantiated from here
gaPopulation.h:36: warning: unused variable 'xsite_'
gaPolicies.h: In member function 'void
StdVectorStorage<T>::create(size_t, size_t) [with T =
Individual<Chromosome<BoostBitsetStorage>, HeapStorage>]':
gaPopulation.h:40: instantiated from 'void Population<Individual,
StoragePolicy>::initialize(gaParameters*) [with Individual =
Individual<Chromosome<BoostBitsetStorage>, HeapStorage>, StoragePolicy
= StdVectorStorage]'
gaSimpleGA.h:152: instantiated from 'void gaSimple<Population,
SelectionPolicy>::initialize(int, char**) [with Population =
Population<Individual<Chromosome<BoostBitsetStorage>, HeapStorage>,
StdVectorStorage>, SelectionPolicy = ProportionateSelector]'
main.cxx:16: instantiated from here
gaPolicies.h:37: error: dependent-name
'std::vector<T,std::allocator<_CharT> >::iterator' is parsed as a
non-type, but instantiation yields a type
gaPolicies.h:37: note: say 'typename
std::vector<T,std::allocator<_CharT> >::iterator' if a type is meant
make: *** [main.o] Error 1=
I try to iterate over it. For some reason, the compiler gives me an
error when I declare
std::vector<T>::iterator iter;
Any ideas why is tihs happening? The code is as follows:
template <class T>
struct StdVectorStorage
{
std::vector<T>* _storage;
void create(size_t p,size_t l)
{
_storage = new std::vector<T>(p);
std::vector<T>::iterator iter;
}
~StdVectorStorage()
{
}
};
g++ -c -o main.o main.cxx -pg -O2 -Wall -Wno-sign-compare
gaPolicies.h: In member function 'void
StdVectorStorage<T>::create(size_t, size_t)':
gaPolicies.h:37: error: expected `;' before 'iter'
gaPopulation.h: In member function 'void Population<Individual,
StoragePolicy>::initialize(gaParameters*) [with Individual =
Individual<Chromosome<BoostBitsetStorage>, HeapStorage>, StoragePolicy
= StdVectorStorage]':
gaSimpleGA.h:152: instantiated from 'void gaSimple<Population,
SelectionPolicy>::initialize(int, char**) [with Population =
Population<Individual<Chromosome<BoostBitsetStorage>, HeapStorage>,
StdVectorStorage>, SelectionPolicy = ProportionateSelector]'
main.cxx:16: instantiated from here
gaPopulation.h:36: warning: unused variable 'xsite_'
gaPolicies.h: In member function 'void
StdVectorStorage<T>::create(size_t, size_t) [with T =
Individual<Chromosome<BoostBitsetStorage>, HeapStorage>]':
gaPopulation.h:40: instantiated from 'void Population<Individual,
StoragePolicy>::initialize(gaParameters*) [with Individual =
Individual<Chromosome<BoostBitsetStorage>, HeapStorage>, StoragePolicy
= StdVectorStorage]'
gaSimpleGA.h:152: instantiated from 'void gaSimple<Population,
SelectionPolicy>::initialize(int, char**) [with Population =
Population<Individual<Chromosome<BoostBitsetStorage>, HeapStorage>,
StdVectorStorage>, SelectionPolicy = ProportionateSelector]'
main.cxx:16: instantiated from here
gaPolicies.h:37: error: dependent-name
'std::vector<T,std::allocator<_CharT> >::iterator' is parsed as a
non-type, but instantiation yields a type
gaPolicies.h:37: note: say 'typename
std::vector<T,std::allocator<_CharT> >::iterator' if a type is meant
make: *** [main.o] Error 1=