Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neurokaotix

I want to make an class inheritance public but I dont know how

This topic is 5899 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

CSprite Sprite; Sprite.Initialize("crate2.jpg"); I use the above code to inherit the functionality of the class CSprite to something I created called Sprite. I''m using Sprite.Render(); in my RenderAll() function where everything in my game is rendered. When I call Sprite.Render() in RenderAll() I get errored out and my debug log says: DXMain.cpp(219) : error C2065: ''Sprite'' : undeclared identifier DXMain.cpp(219) : error C2228: left of ''.Render'' must have class/struct/union type egads! Now, do I have to somehow make Sprite public or global? If so, how do I do that? I''m totally newb lol

Share this post


Link to post
Share on other sites
Advertisement
you need to pass it as a parameter (either as a reference or as a const reference) to whatever functions are using it.

---
Come to #directxdev IRC channel on AfterNET

Share this post


Link to post
Share on other sites
I''m not going to lie, I have little to no idea as to how I can accomplish that. Can you show me how? It would make things a lot easier and I''d be able to learn how to do it.

Share this post


Link to post
Share on other sites
quote:

CSprite Sprite;
Sprite.Initialize("crate2.jpg");



in which file and function is this present?

quote:

Sprite.Render();

in my RenderAll() function where everything in my game is rendered. When I call Sprite.Render() in RenderAll() I get errored out and my debug log says:



in which file is this present?
or better, try posting the code.

are you aware of local variables and objects concept???
i think you are declaring a local variable (CSprite Sprite) in some function and trying to use the same variable in another function (RenderAll()). This is not possible cuz the variable Sprite cease to exist after the first function returns. Also if the RenderAll() is called from the first function, then Sprite object exist but the RenderAll function cannot see it since Sprite is a local variable to the first function.

to solve the problem (this is not the correct way though!)

  
void main()
{
CSprite Sprite;
Sprite.Initialize("crate2.jpg");
// some code

...
RenderAll(&Sprite);
// Some more code

...
}

void RenderAll(CSprite *sprite)
{
// some code

...
sprite->Render();
// some more code

...
}


You should ideally maintain a linked list (or dynamic array) of all the sprites created. When ever you create a sprite object (create it dynamically using new) add this object to the linked list. Then the RenderAll function can accept this linked list as the parameter and traverse through this linked list and call sprite->Render() for each object in the list.

either way, you need to organize the code in a better way...

Share this post


Link to post
Share on other sites

  • 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!