- Κώδικας: Επιλογή όλων
1.main.cpp
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
int main(void) {
showI();//emfanizei tin timi mias global (over multiple files ) variable
increaseI();//auksanei tin timi autis tis globalvariable
i++;
showI();
return EXIT_SUCCESS;
}
2.test.h
#ifndef TEST_H_
#define TEST_H_
extern int i;
void showI();
void increaseI();
#endif /* TEST_H_ */
3.test.cpp
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#include "test.h"
int i;
void showI()
{
cout<<"i= "<<i<<endl;
}
void increaseI()
{
i++;
cout<<"i 've increased i ="<<i<<endl;
}
Otan kanw to run mesa apo eclipse mou emfanizei to lathos
- Κώδικας: Επιλογή όλων
undefined reference to `showI()
enw an dokimasw na to kanw compile mesa apo terminal
- Κώδικας: Επιλογή όλων
g++ main.cpp test.cpp -test.exe
kai run ./test.exe den mou
bgazei kanena lathos alla mou emfanizei swsta
- Κώδικας: Επιλογή όλων
i= 0
i 've increased i =1
i= 2



