Assignment operator and virtual inheritance

Started by
13 comments, last by SmkViper 9 years, 7 months ago

Seems very complicated... perhaps virtual assignment operators and/or making sure you can't assign a class to a different type.

I think implementing a swap() might be even worse.

Advertisement
First, just don't do this. You don't need virtual inheritance and you don't need a funky inheritance structure. Flatten your object relationships, use aggregation, prefer interfaces over base classes, etc. 20 years of C++ and I've never once run into a problem like this that couldn't be fixed with a smarter object structure (remember, computers aren't taxonomists, they don't care about real-world relationships when it comes to OOP; they only care about functional interfaces).

Second, this is the kind of question you should direct at StackOverflow for the language grognards to answer. You'd likely get a full answer with quotes from the standard in like 4.7 seconds if you had posted this over there.

Sean Middleditch – Game Systems Engineer – Join my team!

Second, this is the kind of question you should direct at StackOverflow for the language grognards to answer. You'd likely get a full answer with quotes from the standard in like 4.7 seconds if you had posted this over there.

Lol, you are right.

The first paragraph: I agree with most of it, thanks for the advice. I dont think I can talk about the parts I dont agree with without risking a debate/opinion-exchange. ...so I wont:)

That is an interesting question, but I agree that it probably shouldn't be a concern in practice.

Virtual & multiple inheritance are designed to be used with abstract interfaces... and it doesn't make much sense to have assignment operators for interfaces.
If I have an interface IStream and derived from it I have the implementations DiskStream and NetworkStream, what does it mean when a user writes:


NetworkStream n(...);
DiskStream d(...);
d = n;// "turn my disc-reading stream into a copy of my network-reading stream" WHAT DO YOU WANT FROM ME?!

In this case, I'd probably make IStream non-copyable.

That is an interesting question, but I agree that it probably shouldn't be a concern in practice.

Virtual & multiple inheritance are designed to be used with abstract interfaces... and it doesn't make much sense to have assignment operators for interfaces.
If I have an interface IStream and derived from it I have the implementations DiskStream and NetworkStream, what does it mean when a user writes:




NetworkStream n(...);
DiskStream d(...);
d = n;// "turn my disc-reading stream into a copy of my network-reading stream" WHAT DO YOU WANT FROM ME?!
In this case, I'd probably make IStream non-copyable.


Obviously they want the hard drive to unplug itself from the SATA cable, jam a RJ45 in there, and access it via the network card.

This topic is closed to new replies.

Advertisement