ios is inherited from both, istream and ostream. iostream uses multiple inheritance to inherit istream
and ostream. Hence, iostream would inherit all member variables of ios twice.
To not inherit those members twice, it uses virtual inheritance. For this to work, special requirements when calling constructors apply. E.g. under certain conditions, all further child classes have to call constructors from the virtual base class directly (even if they are not directly subclassed from this class).
The iostream hierarchy itself is not copyable, means they declare their copy constructor private (and never define it). So my guess was, that for your problem the compiler tries to call a constructor of one virtual base class involved which was declared private.
I don't have a firm grasp of multiple virtual inheritance in C++, but I know that this stuff is the biggest reason why a lot of people shun multiple inheritance alltogether. It is one of the most unintuitive and hardest part of C++ and also a part where I would not be surprised at all if I see non-complaince of compilers today.
Anyway, I should not have been so sure about the virtual inheritance thingie in my last post. I made research, and it seems it's not about the multiple inheritance. Looks like VC is completely foobar when it comes to copying exception variables. Or maybe there are some strange definitions about this in the standard. This gives a
link error about a missing NoCopy(const NoCopy&) for me!!1!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
struct NoCopy {
NoCopy(){}
~NoCopy(){}
private:
NoCopy(const NoCopy&);
};
struct Copy : NoCopy {
Copy(){}
Copy(const Copy&):NoCopy(){}
};
int main() {
throw Copy();
return 0;
}
| |
PanGalactic wrote: |
---|
This compiles and runs with VC2010 and g++: |
It doesn't compile in my VS2010. That's my compiler version:
c:\Program Files\Microsoft Visual Studio 10.0\VC\bin>cl /?
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30128.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.
|
Maybe I just have to update... ;-)
Ciao, Imi.