This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
pure virtual method called, context dependent?
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: pure virtual method called, context dependent?
- From: Austin Bingham <abingham at arlut dot utexas dot edu>
- Date: Tue, 14 Aug 2001 09:10:13 -0500 (CDT)
I have encountered a problem with 2.95.2 and .3 which has me stumped. My
application is giving me a "pure virtual method called" error when I run
certain code. However, when I extract the offending code and build it into
a small test frame, it runs just fine. Since it works OK in some cases, I
think I've avoided the thing that commonly cause this error (i.e.
accessing objects which are destroyed or in the process of being
destroyed, etc.).
Does this ring any bells with anyone? Does g++ get confused somehow as the
program size grows? The code below shows the kind of code that's causing
the errors:
==================================================================
template <class A, class B>
class BaseClass : public unary_function<A,B> {
public:
virtual ~Subclass() {}
virtual B operator()(const A& a) = 0;
};
template <class A, class B>
class Subclass : public BaseClass<A, B> {
public:
B operator()(const A& a) { ... impl ... }
};
// Other subclasses of BaseClass follow...not shown
int main(void) {
BaseClass<float, int>* bc = new Subclass<float, int>();
int x = bc(4.2); // this is where it explodes at runtime
^^^^^^^
return x;
}
=====================================================================
That, of course, is greatly pared down and distilled from the actual code
which fails, but it shows the flavor (template inheritance with pure
virtual functions).
So, any help or ideas would be great. I want to try building this with
3.0, of course, and that may clear things up. However, that may not be
acceptable for our project as a whole, so it's not a great solution right
now. Thanks for any help on this.
Austin Bingham
Applied Research Laboratories
abingham@arlut.utexas.edu