Skip to content

Instantly share code, notes, and snippets.

@TonyWhite TonyWhite/esterna.cpp Secret
Last active Oct 3, 2018

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.