Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a virtual function declaration to zero? [duplicate]

Tags:

c++

oop

Possible Duplicate:
Why pure virtual function is initialized by 0?

In C++, what does it mean to set a function declaration to zero? I'm guessing it has to do with the function being virtual, and not actually defined in this class. Found in a header file of code that I'm reading:

virtual void SetValue(double val)=0;

What's going on here?

like image 945
ack Avatar asked Jul 26 '10 21:07

ack


2 Answers

It's a pure virtual function. It makes it so you MUST derive a class (and implement said function) in order to use it.

like image 67
Cogwheel Avatar answered Nov 05 '22 23:11

Cogwheel


This is called a pure virtual member function in C++ lingo. It means, as you guessed, that the function is not defined within the class, but rather has to be implemented in deriving classes. You cannot instantiate classes with pure virtual member functions, pure virtual functions basically behave like abstract methods in Java or C#.

like image 40
haffax Avatar answered Nov 05 '22 23:11

haffax