Using std::array in my class

Apr 14, 2015 at 12:29pm
Hi!

I want to create a class which has similar properties as the std::array container. I also want to make extra constructors and functions in this class.

My questions are:
Is the std::array a class and can I derive a new class from it with custom features? If yes, how can I do it?
If not, how can I use std::array container to create a custom class with similar properties as the std::array?

Thank you.
Last edited on Apr 14, 2015 at 12:30pm
Apr 14, 2015 at 1:24pm
Yes, it is a class, and yes, you can derive from it. Just don't add any of your own data members - std::array does not have a virtual destructor (for good reason). If you're curious I can elaborate, but it is not important right now.

Something to be aware of is that you may break several compiler optimizations - std::array is heavily dependent on the compiler being to optimize it, and by recreating it or inheriting from it you will probably disable those optimizations.
Last edited on Apr 14, 2015 at 1:26pm
Apr 14, 2015 at 1:46pm
Thank you for your reply and explanation.

Can you also advise me about the following. I need to work with 3D geometry primitives like points, vectors, lines, planes etc. My first intention was to create classes for each of those primitives with appropriate constructors, methods and functions. The idea was to use OO part of c++ but I am not sure any more about this.

What is the best way for performing this task?
Apr 14, 2015 at 2:51pm
You should find and use an existing 3D graphics library (e.g. Magnum) and use that instead of writing it all yourself.
Apr 14, 2015 at 2:54pm
Thank you for your help.
Apr 15, 2015 at 1:58pm
Hello, again!

You probably misunderstood me. I do not want to display 3D geometry objects, I only want to work with them on a back end level.

So, I want to be able to create 3 objects called `point` and then define an object `plane` with a normal `vector`, and so on. I only need a few of them, such as point, vector, line, plane, maybe a couple of others. That is all. I do not need all that complex 3D displaying. In general, I do not need to display them at all. It is a purely mathematical task.

What would you recommend for this purpose?

Thank you.
Apr 15, 2015 at 2:01pm
You don't have to use a 3D graphics library to actually display anything; you could do exactly as you suggest and simply work with the mathematical parts of the library. Even though rendering is the primary focus of the libraries, by their own nature they have to have a great deal of mathematical components. A 3D library without 3D math is not complete.

Alternatively, you could look up matrix libraries and see if there are any that have a 3D focus.
Apr 15, 2015 at 2:02pm
Ok, I see what you mean. Thank you.
Topic archived. No new replies allowed.