C
Chris Stankevitz
My intention is to
- Create an abstract base class "Shape" that must be an "Observer"
- Create an class "Square" that is a "Shape" and also an
"ObserverImp"
I thought I could do this like so:
struct Observer
{
virtual void Notify() = 0;
};
struct ObserverImp : public Observer
{
void Notify() {}
};
struct Shape : public virtual 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
Q: How can I do this using c++?
Thank you,
Chris
- Create an abstract base class "Shape" that must be an "Observer"
- Create an class "Square" that is a "Shape" and also an
"ObserverImp"
I thought I could do this like so:
struct Observer
{
virtual void Notify() = 0;
};
struct ObserverImp : public Observer
{
void Notify() {}
};
struct Shape : public virtual 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
Q: How can I do this using c++?
Thank you,
Chris