Skip to content

Instantly share code, notes, and snippets.

@TonyWhite
Last active October 3, 2018 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TonyWhite/070e552314b63b74f7247529c2fd96e2 to your computer and use it in GitHub Desktop.
Save TonyWhite/070e552314b63b74f7247529c2fd96e2 to your computer and use it in GitHub Desktop.
Enigma
Esterna::Esterna()
{
numero = 0;
cout << "Classe dichiarata in .h e costruita in .cpp" << endl;
}
Esterna::~Esterna()
{
cout << "Classe distrutta irrimediabilmente" << endl;
}
void Esterna::setNumero(int num)
{
numero = num;
}
int Esterna::getNumero()
{
return numero;
}
#ifndef ESTERNA_H
#define ESTERNA_H
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Esterna
{
int numero;
public:
//Constructor
Esterna();
//Destructor
virtual ~Esterna();
//Set things
void setNumero(int num);
//Get things
int getNumero();
};
#include "esterna.cpp"
#endif
#include "esterna.h"
int main()
{
Esterna esterna;
return 0;
}
all:
g++ -o main main.cpp
@TonyWhite
Copy link
Author

TonyWhite commented Oct 3, 2018

main.cpp

  • chiama esterna.h

esterna.h

  • previene il caricamento multiplo dell'header
  • include il sorgente dopo la chiusura della classe e prima di #endif

Domanda
Questo previene il caricamento multiplo del sorgente in runtime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment