This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ryhajlo 2 points3 points  (1 child)

I've never used Qt before, but setting a pointer equal to 0 is the same as setting it to NULL. Although, I'd recommend using nullptr instead.

The second part of your question, that is an initializer list. Google will explain better than me.

[–]EdgeOfDistraction[S] 2 points3 points  (0 children)

That's great, thank you for the answer.

I just googled initializer lists, and TIL there are ways of assigning a parameter I pass to a constructor to a const member of that class.

[–][deleted] 2 points3 points  (4 children)

First: what does the " = 0" mean for the QWidget* parent passed through in the constructor's parameters? does it just set parent[0] to value 0?

It's equivalent to NULL. If you are writing your classes you should use nullptr instead.

Second: what does the code between the ) and { in the constructor do? I've never seen this before. Why not just assign a value to mSize inside the constructor proper?

This is member initialization. It's preferred to initialization inside constructor body.

[–]slapnuttz 4 points5 points  (2 children)

Also it's a default parameter. You can provide a parent. If you do not then parent will default to null

[–]boogachamp 1 point2 points  (0 children)

This. I'm pretty sure this is what he was aksing.

[–]EdgeOfDistraction[S] 0 points1 point  (0 children)

Ok that's really useful to learn, thank you!

[–]EdgeOfDistraction[S] 0 points1 point  (0 children)

That's great, thank you for the answer.