class foo
{
public:
foo(){}
~foo(){}
std::vector<mtrl> &mMtrl;
};//end class foo
void dostuff(foo *f)
{
do foo;
}
use it like this
std::vector<mtrl> mtrlList;
foo f;
f.mMtrl = mtrlList;
dostuff(&f);
Pointers to Vectors(fixed Passed in &mTex drrrrr)
Hi all,Im having trouble trying to pass a pointer to a vector, this is what Im doing is it valid.
but the compiler complains say's
error C2758: 'PhongFXRenderData::mtrls' : must be initialized in constructor base/member initializer list
what Im trying to do is replace
dostuff(std::vector<mtrl> &mtrl)
{
}
so I can pass a class of params to this function
if I make the std::vector<mtrl> &mMtrl in the class foo to std::vector<mtrl> *mMtrl; I cant use it in my function it says
cShaderPhongDirectionalLight::SetMaterial' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'Mtrl *'
the function I need to pass mtrl to is defined like this
void SetMaterial(Mtrl *mat){}
is there away I can Pass the vector into a class to pass on to this function.
[Edited by - ankhd on March 13, 2008 11:06:16 PM]
That's not a pointer, it's a reference. They are similar, but not identical.
References cannot be changed once initialized, and they cannot be NULL. Also, in your example you create vector on stack. After you exit the scope, that vector no longer exists.
struct foo { foo( Bar & init_br ) : br( init_br ) {} Bar & br;};void dostuff( foo & f ) { // do the foo};int main() { Bar b; foo f(b); // no & operator, b is passed as reference dostuff(f); // again, no & operator};
References cannot be changed once initialized, and they cannot be NULL. Also, in your example you create vector on stack. After you exit the scope, that vector no longer exists.
still no Idea.
I have this std::vector<IDirect3DTexture9*> mTex; I need to pass the vector to a function that use's one of the textures I can do this if I don't use the vectors, but for the life of me I can't do it with the vector list, can some one help me with this.
this is what I have so far
The above gives me this
1>c:\gamelib\cgameobject.cpp(244) : error C2664: 'cShaderPhongDirectionalLight::Render' : cannot convert parameter 1 from 'std::vector<_Ty> *__w64 ' to 'const std::vector<_Ty> &'
I have this std::vector<IDirect3DTexture9*> mTex; I need to pass the vector to a function that use's one of the textures I can do this if I don't use the vectors, but for the life of me I can't do it with the vector list, can some one help me with this.
this is what I have so far
class obj{public: obj(){} ~obj() { for(UINT i = 0; i < mTex.size(); ++i) SAFE_RELEASE(mTex); } std::vector<IDirect3DTexture9*> mTex;};//end class objSettexture(IDirect3DTexture9 *text);dostuff(std::vector<IDirect3DTexture9*> &mTex){ for(int ctr = 0; ctr < mTex.size(); ctr++); Settexture(mTex[ctr]);}main(){ obj object; dostuff(object.mTex);}
The above gives me this
1>c:\gamelib\cgameobject.cpp(244) : error C2664: 'cShaderPhongDirectionalLight::Render' : cannot convert parameter 1 from 'std::vector<_Ty> *__w64 ' to 'const std::vector<_Ty> &'
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement