By default, the function pointer will be NULL?

Will the following class mean that onPaintCallback is NULL, or should I make it NULL in the class constructor? I want to start checking for NULL before it is assigned a valid pointer.

class AguiWidgetBase { virtual void onPaint(); void (*onPaintCallback)(AguiRectangle clientRect) = 0; public: AguiWidgetBase(void); ~AguiWidgetBase(void); }; 
+1
source share
1 answer

What you have is not legal. You must initialize it in the constructor:

 AguiWidgetBase::AguiWidgetBase() : onPaintCallback(0) {} 

You can use boost::function<void(AguiRectangle)> , which, in addition to flexibility, correctly initializes the null value. You can check this as:

 if (f) // ... 
+6
source

All Articles