Note that there are some explanatory texts on larger screens.

plurals
  1. POConversion between types
    primarykey
    data
    text
    <p>This is a question about class design. I am confuse about how the compiler will deal with those two classes. As a object oriented language C++ need to optimize le layer of abstraction or type abstraction to be efficient. An example that I can think about are iterator. They are a totaly different type than a pointer and yet the compiler can optimise and for example in a for loop be as efficient as a pointer.</p> <p>What I am concern about is how to make those two classes as efficient if they would be only one. The two classes are the mathematic representation of a Point3 and a Vector3.</p> <p>Operation on Point3 are really limited but in mathematic we can make a Vector3 out of a Point3 by substracting it from the Origin. we can also do the oposite by considering the end of the Vector3 as a Point3.</p> <p>An example of this would be to scale a Point3.</p> <pre><code>Point3&lt;float&gt; positionStart; Vector3&lt;float&gt; scale; Point3&lt;float&gt; positionEnd; positionEnd = scale * positionStart; </code></pre> <p>This should convert the <code>positionStart</code> Point3 to a Vector3, do the multiplication and then take the end point of the temporary Vector3 to assign it to the <code>positionEnd</code>.</p> <p>How do we code this efficiently in C++ so that those conversion don't actually happen. Because in the end Point3 and Vector3 are represented by 3 floats. At runtime it should mather if it was a Point3 or a Vector3 but compiler should care about the type not the processor.</p> <p>I hope this is clear I'll try to explain better my confusion if not.</p> <p>thanks</p> <p>** Update ** To focus a bit more the question, this can be done with conversion constructors or conversion. operators. The internal are actually the same. Will the compiler be able to see trough and optimize out, I guess by inlining, those constructors and conversion operators.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload