How can I declare a static memory c ++?

2

I have this code I would like to know what should change to use the (->) instead of using the (point) I think I have to add a new

Lista<Punto> pLista;

pLista.insetarFinal(Punto(8, 1));

pLista.insetarFinal(Punto(7, 2));

pLista.insetarFinal(Punto(1, 3));

pLista.insetarFinal(Punto(9, 4));

pLista.insetarFinal(Punto(4, 5));
    
asked by Fernando Manuel 01.10.2017 в 10:06
source

1 answer

3

You say it wrong: the case that you show, is a variable (or instance) not dynamic . What you want to do is create a dynamic instance .

The static thing ... means something else; -)

Simple:

Lista<Punto> *pLista = new Lista< Punto >;

pLista->insetarFinal(Punto(8, 1));
pLista->insetarFinal(Punto(7, 2));
pLista->insetarFinal(Punto(1, 3));
pLista->insetarFinal(Punto(9, 4));
pLista->insetarFinal(Punto(4, 5));

Instead of creating an instance , you create a pointer and initialize it.

Remember that will not be destroyed alone, you will have to do it by hand when you no longer need it:

Lista< Punto > *pLista = new Lista< Punto >;

...

delete pLista;
    
answered by 01.10.2017 в 10:09