4
In Java:
public class Teste extends Testando
{
private String nome;
private int numero;
public Teste(String teste, String nome, int numero)
{
super(teste);
this.nome = nome;
this.numero = numero;
}
}
What is the command corresponding to super()
in C++
?
I was writing a reply that was the second example, but since you did +1
– Guilherme Nascimento
I think the second seems to me more "organized" and even more common, I do not know how is the standard in C++11 and 14, if there is any pattern, I personally divide the . hpp and the . cpp and make the "super" call on the . cpp, but of course this is how I do, to which I researched a little (unfortunately old links) did not find any definitive pattern, so both examples seem good (although I prefer the second).
– Guilherme Nascimento
I think at first it can also be without the name of the class, for example:
::Testando(teste)
. Not?– Luiz Vieira
@Guilhermenascimento I prefer the second, I put the first to look like what he did. I remember something that becomes problematic when you do the first one, but I don’t remember what. I used little C++, never studied thoroughly. I arranged as Luizvieira said.
– Maniero
I have the impression that the first example is wrong: it is calling the base class constructor and creating a temporary one, which is discarded...probably the compiler should warn. The second mode is the correct way to call the constructor of a base class.
– zentrunix