I am writing a program based on a UML my professor gave us. On the UML, I have the following function:
SetTitle(string) = 0
I am not sure as to what the meaning of = 0 is or even how to declare it.
I am thinking something like
void SetTitle(string) = 0
But I am not sure
Please help
In C++: How do you initialize a static member function?
Doesn't it mean it's a pure virtual function?
It means that you cannot instantiate the class to which the function belongs because it's an abstract class.
example:
class Base {
virtual void SetTitle(string) = 0;//just the interface, no need to define
}
class Derived : public Base {
virtual void SetTitle(string) {
// set title here
}
}
Reply:Well, if, = 0 is written after a function's prototype, it means that it is a pure virtual function and the class which this function is declared is an abstract class. You cannot instantiate an abstract class. But you can inherit from an abstract class and override the pure virtual function.
SetTitle(string) = 0 This prototype is incomplete. Usually setter functions' return type is void. So, you have to inherit a class from your abstract class and then override SetTitle function by defining it.
Pseudo code:
void SetTitle(string name) {this-%26gt;mName = name;}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment