Jump to content
  • Advertisement
Sign in to follow this  
Prune

(C++0x / VC++2010) Inherit move ctor when default ctor is private

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

It seems with the using keyword you cannot specify only some of overloaded functions to be inherited. This creates a design problem for me which someone here might be able to help me with. I have a class that has parts of its structure as follows: class A { public: ... inline A(T mandatory_arg) inline A(A &&other); Image &operator=(A &&other); ... protected: ... private: ... A(void); A(A const &); A &operator=(A const &); ... }; Now, I have several derived classes and since the move ctor and assignment operator have identical bodies in each case, I'd like to inherit them: class B { public: ... using A::A; using A::operator=; ... }; However, I am unable to do so because: error C2876: 'A' : not all overloads are accessible Which is understandable. I might compromise in making the copy ctor and copy assignment public, but I must prevent default construction of A. This leads to the ugly result of having to cast to A any time I want to use the move constructors on the derived classes... any better way? Too bad syntax such as this doesn't work: using A(A &&other);

Share this post


Link to post
Share on other sites
Advertisement
You do realize that if you declare your own constructor, that a default constructor is no longer present unless explicitly declared.

Share this post


Link to post
Share on other sites
Wait, you have multiple derived classes and none of them add anything to the move constructor or assignment? Why do these classes exist then?

Share this post


Link to post
Share on other sites
It's not that much extra typing to write the constructors instead of trying to pull them in with using
class B
{
B(T mandatory_arg a) : A ...
B(A &&other a) : A ...
};
Quote:
Original post by Washu
You do realize that if you declare your own constructor, that a default constructor is no longer present unless explicitly declared.
You do realise that this form of rhetorical question is extremely patronising.

[Edited by - Hodgman on April 15, 2010 11:25:40 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman

inline B(A &&other a) : A(a) {}

This move constructor won't compile, as it'll try to call A(const A &) and not A(A &&). You should add in a std::move() call.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!