Hello,
I'm having a few problems with vector<> and was wondering if anyone can help..
I've tried to find out what's wrong (I've programmed in many langues before just not C++ that often, and I've never used vector<>)
To my understanding.. it's just a type of array created with vector<type>
Now.. I'm proting a forgotten game (Borqueror), to Linux so I can continue it's development. Fixed and rewrote the MS specific code.. but this won't complie at all.
[teval@quantum Game]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
The problem is:
#include "stdafx.h"
#include "Planets.h"
#include "Colony.h"
#include "Technology.h"
#include "Production.h"
#include "Fleet.h"
#include "SolarSystem.h"
#include "Vessel.h"
#include "itoa.h"
const double Facility::GetEffisciency( void )
{
double ans = effisciency;
return ans;
}
void Production::UpdateAllow2Build( const int maxTechLevel )
{
availFacilities.clear();
for( vector<Technology>::iterator it = tt.begin() ; it != tt.end() ; ++it )
{
if( it->techLevel && it->techLevel <= maxTechLevel )
if( CanBuild( it ) )
availFacilities.push_back( it->name );
}
}
const bool Production::Proceed( vector<TurnEvent*> &event )
{
for( vector<Facility>::iterator it = facilities.begin() ; it != facilities.end() ; ++it )
{
vector<Technology>::iterator pos = find_if( tt.begin() , tt.end() , bind2nd( mem_fun_ref( &Technology::IsNamed ) , it->name.c_str() ) );
if( (pos->mask & 0x04) == 0x04 )
it->SetOutput( pos->prodQty * it->GetEffisciency() * it->nr );
if( (pos->mask & 0x10) == 0x10 )
{
if( pos->name == "Natural Resources" )
it->SetOutput( pos->prodQty * planet.GetOre() );
else if( pos->name == "Soil Composition" )
it->SetOutput( pos->prodQty * planet.GetSoil() );
else if( pos->name == "Planet Energy Rsc." )
it->SetOutput( pos->prodQty * planet.GetEnergy() );
else if( pos->name == "Sunrays Factor" )
it->SetOutput( pos->prodQty * planet.GetSunFactor() );
}
}
int n = 0;
bool ans = !buildStack.empty();
for( vector<BuildInProgress*>::iterator pos = buildStack.begin() ; pos != buildStack.end() ; ++pos )
{
Building( pos );
if( pos->IsBuilt() )
{
ans = true;
vector<Facility>::iterator at = find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility::IsNamed ) , pos->name.c_str() ) );
if( at != facilities.end() )
at->nr += 1;
else
{
vector<Technology>::iterator ins = find_if( tt.begin() , tt.end() , bind2nd( mem_fun_ref( &Technology::IsNamed ) , pos->name.c_str() ) );
if( (ins->mask & 0x08) == 0x08 )
{
SolarSystem &ss = planet.ss;
Fleet *f = 0;
for( multimap<string,Fleet*>::iterator it = PlayGame::fleets.lower_bound( species ) ; it != PlayGame::fleets.upper_bound( species ) ; ++it )
if( it->second->GetPosition() == ss.GetPosition() )
{
f = it->second;
break;
}
if( !f )
{
bool ok = false;
int i = 0;
string fleetName;
while( !ok )
{
char tmp[10];
fleetName = species + itoa( ++i , tmp , 10 );
for( multimap<string,Fleet *>::iterator it = PlayGame::fleets.lower_bound( species ) ; it != PlayGame::fleets.upper_bound( species ) ; ++it )
if( it->second->name == fleetName )
break;
ok = (it == PlayGame::fleets.upper_bound( species ));
}
f = new Fleet( species , fleetName );
f->Setup( ss.GetPosition() , &planet );
f->Setup();
}
f->push_back( new Vessel( ins->prodName , species ) );
}
else
{
facilities.push_back( Facility( *ins , planet.GetEffisciency( species ) ) );
facilities.back().nr = 1;
}
}
event.push_back( this );
n += 1;
}
}
if( n > 0 && ans )
{
while( (pos = find_if( buildStack.begin() , buildStack.end() , mem_fun_ref( &BuildInProgress::IsBuilt ) )) != buildStack.end() )
buildStack.erase( pos );
UpdateAllow2Build();
}
return ans;
}
void Production::Building( BuildInProgress *bip )
{
for( vector<pair<string,int> >::iterator it = bip->buildRequisite.begin() ; it != bip->buildRequisite.end() ; ++it )
{
vector<Facility>::iterator pos = facilities.begin();
while( it->second )
{
if( (pos = find_if( pos , facilities.end() , bind2nd( mem_fun_ref( &Facility:
oesProduce ) , it->first.c_str() ) )) != facilities.end() )
if( pos->GetOutput() >= it->second )
{
pos->AddOutput( -it->second );
it->second = 0;
}
else
{
it->second -= pos->GetOutput();
pos->SetOutput( 0 );
}
else
break;
++pos;
}
}
}
const bool Production::CanBuild( Technology *t )
{
if( !t->request.empty() )
if( find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility::IsNamed ) , t->request.c_str() ) ) == facilities.end() )
return false;
for( vector<pair<string,int> >::iterator it = t->inputList.begin() ; it != t->inputList.end() ; ++it )
if( find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility:
oesProduce ) , it->first.c_str() ) ) == facilities.end() )
return false;
for( it = t->buildRequisite.begin() ; it != t->buildRequisite.end() ; ++it )
if( find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility:
oesProduce ) , it->first.c_str() ) ) == facilities.end() )
return false;
return true;
}
/*
void Production::UpdateAllow2Build( const int maxTechLevel )
{
availFacilities.clear();
for( vector<Technology>::iterator pos = tt.begin() ; it != tt.end() ; ++it )
{
if( pos->techLevel && pos->techLevel <= maxTechLevel )
if( CanBuild( pos ) )
availFacilities.push_back( it->name );
}
}
*/
The error message I get:
c++ -c -fno-for-scope -fno-const-strings -I../Source -I../Source/Game -I../Source/Distribution -I../Source/Include -I../Source/Utils -I/usr/local/include ../Source/Game/Production.cpp
../Source/Game/Production.cpp: In member function `void
Production::UpdateAllow2Build(int)':
../Source/Game/Production.cpp:26: no matching function for call to `Production
::CanBuild(__gnu_cxx::__normal_iterator<Technology*, std::vector<Technology,
std::allocator<Technology> > >&)'
../Source/Game/Production.h:112: candidates are: const bool
Production::CanBuild(Technology*)
../Source/Game/Production.cpp: In member function `const bool
Production::Proceed(std::vector<TurnEvent*, std::allocator<TurnEvent*> >&)':
../Source/Game/Production.cpp:57: conversion from `
__gnu_cxx::__normal_iterator<BuildInProgress*, std::vector<BuildInProgress,
std::allocator<BuildInProgress> > >' to non-scalar type `
__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >'
requested
../Source/Game/Production.cpp:57: no match for `
__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >& !=
__gnu_cxx::__normal_iterator<BuildInProgress*, std::vector<BuildInProgress,
std::allocator<BuildInProgress> > >' operator
/usr/local/include/allegro/inline/fix.inl:78: candidates are: int
operator!=(fix, fix)
/usr/local/include/allegro/inline/fix.inl:79: int
operator!=(fix, int)
/usr/local/include/allegro/inline/fix.inl:80: int
operator!=(int, fix)
/usr/local/include/allegro/inline/fix.inl:81: int
operator!=(fix, long int)
/usr/local/include/allegro/inline/fix.inl:82: int
operator!=(long int, fix)
/usr/local/include/allegro/inline/fix.inl:83: int
operator!=(fix, float)
/usr/local/include/allegro/inline/fix.inl:84: int
operator!=(float, fix)
/usr/local/include/allegro/inline/fix.inl:85: int
operator!=(fix, double)
/usr/local/include/allegro/inline/fix.inl:86: int
operator!=(double, fix)
../Source/Game/Production.cpp:59: no matching function for call to `Production
::Building(__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >&)'
../Source/Game/Production.h:118: candidates are: void
Production::Building(BuildInProgress*)
../Source/Game/Production.cpp:60: request for member `IsBuilt' in `
*(&pos)->__gnu_cxx::__normal_iterator<_Iterator, _Container>:
perator->()
const [with _Iterator = BuildInProgress**, _Container =
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> >]()', which
is of non-aggregate type `BuildInProgress*'
../Source/Game/Production.cpp:63: request for member `name' in `
*(&pos)->__gnu_cxx::__normal_iterator<_Iterator, _Container>:
perator->()
const [with _Iterator = BuildInProgress**, _Container =
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> >]()', which
is of non-aggregate type `BuildInProgress*'
../Source/Game/Production.cpp:68: request for member `name' in `
*(&pos)->__gnu_cxx::__normal_iterator<_Iterator, _Container>:
perator->()
const [with _Iterator = BuildInProgress**, _Container =
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> >]()', which
is of non-aggregate type `BuildInProgress*'
../Source/Game/Production.cpp:113: no match for `
__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >& =
__gnu_cxx::__normal_iterator<BuildInProgress*, std::vector<BuildInProgress,
std::allocator<BuildInProgress> > >' operator
/usr/include/c++/3.2.2/bits/stl_iterator.h:571: candidates are:
__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >&
__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> >
>:
perator=(const __gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >&)
../Source/Game/Production.cpp:114: no matching function for call to `
std::vector<BuildInProgress, std::allocator<BuildInProgress> >::erase(
__gnu_cxx::__normal_iterator<BuildInProgress**,
std::vector<BuildInProgress*, std::allocator<BuildInProgress*> > >&)'
/usr/include/c++/3.2.2/bits/stl_vector.h:647: candidates are:
__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >
std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >) [with _Tp = BuildInProgress, _Alloc =
std::allocator<BuildInProgress>]
/usr/include/c++/3.2.2/bits/stl_vector.h:670:
__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >
std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >) [with _Tp = BuildInProgress, _Alloc =
std::allocator<BuildInProgress>]
../Source/Game/Production.cpp: In member function `void
Production::Building(BuildInProgress*)':
../Source/Game/Production.cpp:137: warning: assignment to `int' from `double'
../Source/Game/Production.cpp:137: warning: argument to `int' from `double'
make: *** [../Source/Game/Production.o] Error 1
I have no clue what to do
I know Technology as a type is defined in Technology.h, included.
And if I define any of those types without vector they work fine.. baffeled.
Thanks