views:

97

answers:

3

hi,

i don't understand assignment in the following line. i think, setBit is a function but it's assigned a value.

bool setBit(const unsigned int which) = 0;
+4  A: 

This is a virtual function. when you declare a function and assign it 0 you are creating a function without an implementation

When you inherit this class you can them create a concrete implementation for this function

Raphael
+11  A: 

It's not assignment. It indicates a pure virtual function. A class with one or more pure virtual functions is called an "abstract class", and cannot be instantiated on its own. Derived classes must implement the function in order to avoid being abstract classes themselves. So the meaning of =0 here is, "my derived classes will provide this function".

Steve Jessop
+3  A: 

I assume that you missed the word virtual before bool. It's the declaration of an abstract function in a class. In C++ abstract functions are called pure virtual functions and you tell the compiler that it is abstract by specifying = 0 at the end of the declaration.

Gabriel