How to pass the class (Test2 test2) as reference in the ("super") C ++ constructor?

1

Based on this response In C ++ which the command corresponding to super () of Java?

Class Teste2{
int x;
int y;
public:
  Teste2(int x, int y){
.
.
.
}
}
class Testando{
 Teste2 *teste2;
public:
   Testando(Teste *teste2)
{.
 .
 .
 .
class Teste : public Testando {
    string nome;
    int numero;
    public:
         //Supondo que Teste2 teste2 foi instanciado na Classe Testando
        Teste(Teste2 *teste2, string nome, int numero) : Testando(teste2) {      
            this.nome = nome;
            this.numero = numero;

How to pass a class reference in the constructor?

    
asked by anonymous 27.03.2016 / 21:51

1 answer

1

The code has several small problems, I do not even know what to say to clarify the doubt of the question because I did not understand it, nor do I know if it has a specific doubt. There was a code played without too much discretion and you could not even test it. Note that I did not change anything to make it work, I was fixing basic syntax errors and what else could be a doubt is the change from operator . to operator -> to this . >

#include <string>
using namespace std;
class Teste2 {
    int x;
    int y;
    public:
        Teste2(int x, int y) {}
};
class Testando {
    Teste2 *teste2;
    public:
        Testando(Teste2 *teste2) {}
};
class Teste : public Testando {
    string nome;
    int numero;
    public:
         //Supondo que Teste2 teste2 foi instanciado na Classe Testando
        Teste(Teste2 *teste2, string nome, int numero) : Testando(teste2) {      
            this->nome = nome;
            this->numero = numero;
        }
};
int main() {
    auto teste = Teste(new Teste2(1, 2), "joão", 1);
}

See working on ideone .

To tell you the truth I think most of these codes do not make sense and I do not believe this is teaching something really useful.

    
27.03.2016 / 23:55