Doubt classes c++

Asked

Viewed 99 times

0

Good morning guys! I’m seeing classes and I saw this syntax in one of the examples:

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

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

  • 5

    What context? The question is bad because one is missing. Add information to make the question understandable.

  • Alexsander, I suggest you pay attention to the comments that other users leave on their questions, they usually have valuable tips so you can make your question clear and responsive to community members.

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 its resources.

This is implemented with template method so that it can be reused for any type you want to use, any class declared that there is a template method must follow along with it the type you want 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 dynamical vector that stores addresses of instances of line

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

Not forgetting that the & before variable indicates memory address of the variable and not content of the variable... Search by pointers if you are not aware of pointers... If you want more details about templates (how to create for example) search about templates

0

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

It’s hard to say more since you don’t have as much information than what you’re trying to do. But roughly speaking, that’s what the template means <line *>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.