Doubts c ++ classes [closed]

0

Good morning guys! I'm seeing classes and I've seen this syntax in one of the examples:

vector<line *>line_table;
vector<line *>::iterator iterator;
line parser * basic_parser;
long current_line;

What does this template mean with <line *> ( vector <line *>line_table ), can someone explain me the context?

    
asked by anonymous 04.10.2015 / 19:58

2 answers

1

The STL includes several data structures to the developer one of them is the vector, which is a dynamic vector, there are several other structures a quick search and you will see their resources.

This is implemented with template method so that it can be reused for any type that is to be used, any declared class that exists a template method must accompany with it the type that one wishes to work, that is, what is between keys as in the example below:

pilha<int> a; // Uma pilha de inteiros
a.empilhar(1); // Empilha inteiros

pilha<pessoa> p; // Uma pilha de pessoas
p.empilhar(new pessoa("João", "155155155-15")) // Instancia uma nova pessoa e a empilha

In short, vector line_table; is a vector of pointers to line ... That is, a dynamic vector that stores addresses of line instances

vector<line *> line_table;
line l_exemplo; // Instancia de line
line_table.push_back(&l_exemplo); // inseri no final do vetor o endereço da variavel l_exemplo

Remembering that & before the variable indicates the memory address of the variable and not the content of the variable ... Search for pointers if you do not know pointers ... If you want more details about templates (like creating for example) search about templates

    
06.10.2015 / 16:00
0

vector<line *> line_table means that you are creating a pointer vector for type line .

It's hard to say more because you do not have so much information of what you're trying to do. But roughly, that's what the <line *> template

    
04.10.2015 / 20:25