Typedef Structure Inheritance
John Lenz
jelenz@students.wisc.edu
Tue Nov 26 15:31:00 GMT 2002
Hi. I am getting an error when compiling some code and I was able to
distill it down to this code
typedef struct {
virtual const char *blah() {
return "Heya::blah";
}
} Heya;
struct Grok : public Heya {
virtual const char *blah() {
return "Grok::blah";
}
};
int main() {
Grok *g = new Grok();
delete g;
return 0;
}
When running gcc 3.2.1 (command line "g++ -c broken.cc") with the
latest gcc-3.2 packege in Debian Unstable I get the following error...
borken.cc:10: redefinition of `const char _ZTS4Heya[6]'
broken.cc:10: `const char _ZTS4Heya[6]' previously defined here
But when running it with gcc-2.95.4 (again, the latest package in
Debian Unstable) the file compiles without error. Is this a bug in
gcc? or is the above code not ISO C++ compilant and that is why gcc3.2
is bombing on it? It is kinda a wierd construction and I am not sure
that it is even valid C++ code. One interesting thing to note, remove
the "new" and "delete" lines from the main function and the error is
not generated, even with gcc3.2
John
More information about the Gcc
mailing list