What is the process in C ++ to use headers? [closed]

-2

What is the process in C ++ to use headers and then create an implementation file with the same file name.h for functions?

Good, I would like to know what the process would be in detail to be able to do this.

    
asked by Nizar4790k 23.12.2017 в 03:48
source

1 answer

0
#ifndef ALGO_H
#define ALGO_H
// Declaraciones
#endif // ALGO_H

In c ++ all the lines that start with # are instructions for the compiler, the first line uses an if to check if ALGO_H has been declared if this did not happen then proceed with the code, in the following line it is declared ALGO_H, in this way if something.h runs again the code will be ignored since ALGO_H has already been declared. This is so to avoid that functions or everything you place there be declared more than once.

If you mean how to declare the functions then: something.h

#ifndef ALGO_H
#define ALGO_H
typedef struct {
    char *name;
    char *value;
} Campo;

Campo *obtener_campos(int id);
int leer_entrada(char *nombre, char ciudad[256]);
#endif // ALGO_H

algo.cpp

#include "algo.h"
Campo *obtener_campos(int id)
{
//Funcion
}
int leer_entrada(char *nombre, char ciudad[256])
{
//Funcion
}

As the functions are normally declared in the cpp file and the h is repeated the functions with the same parameters only that they are not implemented and put the; end of line.

    
answered by 23.12.2017 / 04:07
source