Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see the problem with reusing the same identifier within different namespaces, that was they were created for after all.</p> <p>However I would strongly urge you NOT to 'simulate' the inclusion of math::Rectangle. If you need the file then include it, but what you are doing is called copy/paste programming, and it leads to a good number of problems, essentially because your two pieces of code are not synchronized so any bug fix / feature addition to one is not reported on the other.</p> <p>EDIT: answer to the Edit ;)</p> <p>It is not clear from the comments so I will state it:</p> <p>If you need the dependency (because you really USE the functionality offered), then you HAVE to include the header. On the other hand, if you only use inheritance to get something that have 4 corners and nearly no method, then you're better up rolling a new Rectangle class with the minimum functionality.</p> <p>I can think of an edge case though. I am under the impression that you are not so much interested in the functionality but in fact interested in the possibility of reusing the methods in the Math library that have been tailored to take a math::Rectangle as a parameter.</p> <p>According to Herb Sutter (in C++ Coding Standards I think), the free functions that are bundled with a class are part of the class public interface. So if you want those classes, you actually need the inheritance.</p> <hr> <p>Now I can understand that you may have some reluctance in including a library that may be huge (I don't know your Math library). In this case you could consider splitting the Math library in two:</p> <ul> <li>A MathShapes library, comprising the basic shapes and the methods that act upon them</li> <li>A Math library, which includes MathShapes and add all the other stuff</li> </ul> <p>This way you would only depend on the MathShapes library.</p> <p>On the other hand, if you absolutely do not want the dependency, then a blunt copy/paste will do, but your solution of testing the presence of Math::Rectangle by testing the presence of its header guard is ill-fitted:</p> <ul> <li>It only works if you get the header guard correctly</li> <li><strong>AND</strong> if the include is actually performed <strong>BEFORE</strong> the include of Graphics::Rectangle</li> </ul> <p>Note that in the case in which Graphics::Rectangle is included before Math::Rectangle you may have some compilation issues...</p> <p>So make up your mind on whether or not you want the dependency.</p>
 

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