ho trovato il seguente esempio e non mi è chiaro come il main abbia visibilità di my_functions.cc a meno che non si utilizzi il make o quant'altro
Se si compila direttamente il main.cc si ha segnalazione di errori. Se nel file main.cc si inserisce la riga #include "my_functions.cc" è considerata un asporca, come sistemare le cose in modo pulito mantenendo prototipi ed implementazioni in file separati?
grazie
codice://file: my_functions.h void a( void ); // function prototype void b( void ); // function prototype void c( void ); // function prototype int x = 1; // global variablecodice://file: my_functions.cc #include “my_functions.h” void a( void ) { int x = 25; // initialized each time a is called ++x; } void b( void ) { static int x = 50; // Static initialization ++x; } void c( void ) { x *= 10; }codice://file: main.cc #include “my_functions.h” int main() { int x = 5; // local variable to main a(); // a has automatic local x b(); // b has static local x c(); // c uses global x cout << "local x in main is " << x << endl; return 0; }


Rispondi quotando