Jump to content
  • Advertisement
Sign in to follow this  
ankhd

Pointers to Vectors(fixed Passed in &mTex drrrrr)

This topic is 3871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,Im having trouble trying to pass a pointer to a vector, this is what Im doing is it valid.

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);





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]

Share this post


Link to post
Share on other sites
Advertisement
That's not a pointer, it's a reference. They are similar, but not identical.

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.

Share this post


Link to post
Share on other sites
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



class obj
{
public:
obj(){}
~obj()
{
for(UINT i = 0; i < mTex.size(); ++i)
SAFE_RELEASE(mTex);
}

std::vector<IDirect3DTexture9*> mTex;
};//end class obj


Settexture(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> &'

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!