Checking for nullpointer not working

My if is not checking if pointer is initialized. What am i doing wrong ? In Wt hangman tutorial files they have done it this way and for them it works.

1
2
3
4
5
6
7
8
9
10
11
12
13
IndexWidget *index_;

void PictureAlbum::showIndex() {
	if (!index_) {
		index_ = new IndexWidget(mainStack_);
		std::cout << index_ << std::endl;
	}
	std::cout << index_ << std::endl;
	

	mainStack_->setCurrentWidget(index_);
	index_->update();
}

It's not possible to check if a pointer has been initialized, only if it equal or not to zero, which is what you're doing. If you don't actually initialize it to zero, the value is undefined (probably non-zero).
Ahaa... i see my error. On me relying too much on the Wt tutorials and forgot the basics of C++... Always initialize pointers...
Topic archived. No new replies allowed.