Re: Why doesn't this multiple virtual inheritance code compile?
On Jan 2, 3:46 pm, "Alf P. Steinbach" <alf.p.steinbach
+use...@gmail.com> wrote:
If you run into any problems then please post to a new thread with your
exact code and compiler invocation.
Alf,
I attempted what you suggested (minus the style, factory, auto_ptr,
and new thread suggestions). What I came up with did not compile.
(Compiler invocation appears below). Would you please tell me how I
can modify this code so that it compiles and implements:
- Create an abstract base class "Shape" that must be an "Observer"
- Create a class "Square" that is a "Shape" and uses "ObserverImp" to
implement the "Observer" behavior.
Thank you,
Chris
//-----
struct Observer
{
virtual void Notify() = 0;
};
struct ObserverImp : public virtual Observer
{
void Notify() {}
};
struct Shape : public Observer
{
};
struct Square : public Shape, public ObserverImp
{
};
Shape* ShapeFactory()
{
return new Square;
}
//-----
$ g++ -Wall -c test.cpp
test.cpp: In function 'Shape* ShapeFactory()':
test.cpp:21:14: error: cannot allocate an object of abstract type
'Square'
test.cpp:16:1: note: because the following virtual functions are
pure within 'Square':
test.cpp:3:16: note: virtual void Observer::Notify()
test.cpp:22:1: warning: control reaches end of non-void function