Jump to content
  • Advertisement
Sign in to follow this  
deathwearer

Problem using struct inside my class

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

I'm making a small game with Directx and I'm having problem to use my struct inside my class. I have this custom one : struct CUSTOMVERTEX { FLOAT x, y, z; DWORD color; }; In my class header i define it like that CUSTOMVERTEX g_Vertices; The problem is that when i use it inside a subfunction i do this CUSTOMVERTEX g_Vertices[]= { {-100.0f, 0.0f, 0.0f, 0.0f, 1.0f }, {-100.0f, 200.0f, 0.0f, 0.0f, 0.0f }, {100.0f, 0.0f, 0.0f, 1.0f, 0.0f }, {100.0f, 200.0f, 0.0f, 1.0f, 1.0f }, }; I don't need to indicate the size of this struct. But i can't do it when it's inside my class since i can only add the value like that at the declaration of the struct. Normaly i should do g_Vertices[0].x = 1 g_vertices[0].y = 2 etc etc. Is there any faster way to set my value inside my struct without adding the value one by one and telling all the time which case of the struct i want to add it? If i'm not clear enought tell me.

Share this post


Link to post
Share on other sites
Advertisement
1. "CUSTOMVERTEX g_Vertices;" defines a single CUSTOMVERTEX, while "CUSTOMVERTEX g_Vertices[] = {...}" defines an array of CUSTOMVERTEX. Totally different. If you don't explicitly set the size of the array, it is automatically set to the number of elements you initialize it with. In your example, your array has 4 elements.

2. If you define g_Vertices in the class and then also define g_Vertices in a function, those are two totally different variables, even though they have the same name.

3. No, in general, there is no faster way of initializing a non-POD class. However, there may be some tricks or optimizations, but if initialization is not the bottleneck, then there isn't really a need to make it faster.

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!