0

We cannot use constructors if we want that whenever a pointer is declared, it should be NULL. Am I right Sir?
if I declare student *head, *tail, where student is a class, can I make my pointers automatically make NULL using default constructor?

3
Contributors
3
Replies
14
Views
4 Years
Discussion Span
Last Post by Moschops
1

Pointers are built-in types, they don't have constructors per se. If you want your ppointers to be null, make them null explicitly.

student *head = 0;
student *tail = 0;

Assuming those pointers are members of another class then you can certainly use the default constructor to make them null.:

class foo {
public:
    foo(): head(0), tail(0) {}
private:
    student *head, *tail;
};

Edited by deceptikon

1

The same way you use it in any function. main is just a function

Edited by Moschops

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.