first posting so please be gentle!
I have an interface that's like this
public interface I_Hospital{
public void registerObserver(I_Person p);
public void removeObserver(I_Person p);
public void notifyObservers();
public void addWard(Ward ward);
}
Now, if I want to recreate this in C++, is it correct to do the following:
IHospital.h
Class IHospital{
public:
virtual void registerObserver(IPerson p) = 0;
etc...
}
Is this the correct implementation on an Interface in C++??
Thanks, Patrick
virtual _signature_ = 0;gives it the same semantics as an interface in Java.. That said, you may want to change it tovirtual void registerObserver(IPerson &p) = 0;using a reference to p, rather than just passing it in. Since C++ defaults to call by value, what you've written will not work the same as Java, converting to a reference produces about the same results as your Java code.