• Advertisement
Sign in to follow this  

Size of an array by its reference

This topic is 3741 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
Advertisement
Maybe you could pass only the reference to the mesh onto the function ,and then query its size inside the createMesh() function.

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