Unfamiliar constructor of the class.

Considering the following constructor of the class DadosBarraRolagem,
can I substitute this

1
2
3
DadosBarraRolagem():barraRolagem(NULL),posicao(Zoom::Oposta),modo(Qt::ScrollBarAsNeeded)
{
}

by this

1
2
3
4
5
DadosBarraRolagem(): barraRolagem(NULL)
{
        setPosicao(Zoom::Oposta);
        setModo(Qt::ScrollBarAsNeeded);
}

Why the first could be better? There are substantial differences besides the increase of two lines of code?

Thanks in advance.
Last edited on
The first uses the member initializer list. The second is not initializing it is assigning. What that means is using the second method the Objects members are default initialized before it ever reaches the inner portion of the curly braces. Then it assigns the value using the method. Essentially doing double duty.
the increase of two lines of code

You can split the first code in more lines if you like. Having everything on one line can be hard to read.
Topic archived. No new replies allowed.