Skip to main content
GameDev.net gamedev.net
🔒 Locked

hmm vector headache

Started by veiled eagle Apr 25, 2006 at 7:42 AM 7 replies 1.1k views
Original Post
veiled eagle
veiled eagle
Hey heres a stupid question why won't this call work, it gives me a bunch of conversion errors
Quote:
std::vector * boidIndex; Boid * pBoid = boidIndex[boidId];
Quote:
error C2440: 'return' : cannot convert from 'std::vector<_Ty>' to 'Flock *const ' with [ _Ty=Flock * ]
its most likely something simple, but my brain and patience are getting a bit worn...
dave
dave
Is it definately that lin causing any problems because i dont see any Flock there.

Dave
Graham11
Graham11
AT the least, you'll need a cast. Recommended std::vector usage would use iterators etc. A right pain, but presumable 'safer' than pointers...
CTar
CTar
boidIndex is a pointer to a std::vector, are you sure you don't mean to do like this?
std::vector<Boid*> boidIndex;

If you know what you are doing and want to keep it a pointer for some reason, then you need to dereference the pointer before using, like this:
Boid * pBoid = (*boidIndex)[boidId];
veiled eagle
veiled eagle
im having errors with a few object types its all the same errors just different types

Quote:

std::vector * flockIndex;

Flock* pFlock = flockIndex[flockId];


Quote:

error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'Flock *'
with
[
_Ty=Flock *
]

Evil Steve
Evil Steve
Quote:
Original post by veiled eagle
im having errors with a few object types its all the same errors just different types

Quote:

std::vector * flockIndex;

Flock* pFlock = flockIndex[flockId];


Quote:

error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'Flock *'
with
[
_Ty=Flock *
]



Quote:
Original post by CTar
boidIndex is a pointer to a std::vector, are you sure you don't mean to do like this?
std::vector<Boid*> boidIndex;

If you know what you are doing and want to keep it a pointer for some reason, then you need to dereference the pointer before using, like this:
Boid * pBoid = (*boidIndex)[boidId];
veiled eagle
veiled eagle
Thanks CTar that was it, i knew it was easy. sleep time for me for obvious reasons :P
Endar
Endar


Turns out somebody already said everything I had. Almost word for word.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.