Note that I am working in C ++ 03, and I am trying to design a non-replicable object, and to prevent the compiler from considering that underlying-declared per constructor on that class. This is a unit test for sustainability I am developing. Consider that I have two main objects: a core library object, (With the code given below, I have my own Compiling these results: The C ++ 03 compiler is not possible to prevent it from declaring a copy constructor for ... compiler will consider introducing I do not want the compiler to consider these copy constructions. I could . But I would not want to, because it has the ability to make my nose a little smelly and non-copied words / to promote In this case, there is a way to prevent the compiler from considering the built-in per constructor without changing the code on the call-site: ? Your opacity is that The trick is to create a surcharge which is a better match, for example corresponds to any value exactly , and thus there is a better match than a surcharge that requires conversion . However, this is very simple, because in fact you really want to make your In C +03, we use Boost, and we can not use the default template argument: Now you are guaranteed that delete +11 my Are not available for.
root , and special-case object generated under the test,
branch . I am trying to develop a test stability class,
stability which handles the drawbacks of setting up & amp; Talking to the core
root object, this is a simplified example of what I have made so far:
noncopyable is defined, except)
#include & lt; Boost / utility.hpp & gt; #include & lt; Boost / noncopyable.hpp & gt; Square root {}; Class Stability: Public Promotion: Non-CoCAPPable {Public: Stability (Root and Root): Mairoot (Route) {} Private: Route & amp; MRoot; }; Classroom branch: public route, public stability {public: branch (): stability (* this) {}}; Int main () {branch branch; }
main.cpp: "branch" in constructor :: branch () a ???? Main.cpp: 30: 23: Error: Overloaded call fixtures (branch & amp;) ??? Main.cpp: 30: 23: Note: Candidates are: main.cpp: 13: 5: Note: Stability :: Stability (root) main.cpp: 8: 7: Note: Stability :: Stability ( Const fixtures & amp;)
stability unless I Do not declare at least one on your own. But even:
private announcements to
stabilization in the
branch . Initial list:
stability (* this)
stability (static_cast & lt; root & amp;; (* this))
by
constant : noncopyable .
Sustainability (* )
< P> If class definition is not expired legally declares a copy constructor, one is declared completely.
this a
Root & amp; and
can force both with stability and , and both conversions are equally good (i.e. derivative-to-base conversion).
template < Typename T & gt; Stability (T & amp; A / C)
stability not worth being manufactured from nothing. Instead, you want it to be the only thing that can disable the external constructor with some SFINAE magic. First C ++ 11 edition:
#include & lt; Type_traits & gt; Template & lt; Typename T, typename = typename std :: enable_if & lt; Std :: is_base_of & lt; Route, Tac: :: Value & gt; :: type & gt; Stability (t & amp; x): mRoot (x) {}
T has been taken from the
route . The overload of this templated manufacturer with
T = branch is an exact match, the copy is better than the constructor, and therefore it has been chosen as the best overload.
No comments:
Post a Comment