Jump to content
  • Advertisement
Sign in to follow this  

Size of an array by its reference

This topic is 4007 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 have a function that's called like this:
Object.createMesh(mesh, (sizeof mesh)/(sizeof mesh[0]));
mesh is a struct containing vertex information, and createMesh passes along that information by use of a pointer so it can be displayed with glVertexPointer(). As it is right now, createMesh works as it should, but I don't want to keep entering the size of the mesh array as a second argument. I tried making a wrapper function so you only use the name of the struct array, but I don't know how to pass the size of the array by a reference. It could be used with any mesh, so the array has no known bounds.

Share this post

Link to post
Share on other sites
Use std::vector.

If not, then provide some simple wrapper to array:

template < typename T >
struct Array {
size_t size;
T *data;

Note that this isn't any safer than with raw pointers.

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!