No! What you have there is an uninitialized pointer, which is a very bad bug.
Base *b;
declares a pointer to an object of class Base
. A pointer is an address of a memory location. When a pointer is uninitialized, it contains an address, but you have no way of knowing what that address is. So, if you use this pointer, as in your example, the behavior is undefined.
Most likely the pointer contains an address of a part of memory that you are not allowed to access, and running your code will cause a segmentation fault. This is actually the best case scenario.
In the worst case, the pointer points to some valid memory, which will be interpreted as an object of class Base
. Then, if you modify that memory, you would be corrupting it, causing errors which are very hard to track down.
Occasionally, this bug may have no ill effects. In your case, your class has no data members, and so the member functions you call do not modify the object or access any of its data. However, if you modify this class to have some data, and add functions that modify it, you are in for a nasty surprise.
When you declare a pointer, you should make it point to something. You can make it point to a new object on the heap by calling new
, or you can set to be an address of an existing object using &
(address of) operator. Alternately, you can set it to nullptr
, so that you can later check it for being ``NULL`.
Better yet, avoid using raw pointers, and use smart pointers instead.