• Advertisement
Sign in to follow this  

what do you think of the following code design

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

Say we need to have a matrix class for special functionality. The matrix is saved as a size 4x4=16 array of floats: float *mat = new float[16]; Now I've come across to aproaches. 1.) Hide the internal representation completely by using only the class. 2.) work with matrices as float *mat pointers. Then have a class to encapsle it whenever needed like so: Matrix mat(mymat); mat.dosomething(...); I would say I think 1 is better but I'm curious as to whether anyone has any serious reasons not to use 2. I came across this in team projects. Someone used float arrays for matrices and now I have to work with them, so restructure everything or adapt with version 2? -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
To use a matrix class fully with a graphics API, you'll need to expose the internal storage anyway. For example, opengl expects float*s.

Share this post


Link to post
Share on other sites
Well, GL expects const float*s, so you don't need to expose a mutating access to the internals, just a const one.

Share this post


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

  • Advertisement