use same int in different files
I tried my code this day and then I come to one problem..
how to use same int variabel in different cpp files?
i have seen people writing extern int??
if i want to read in one file if for example int hello is larger than 10 and int hello is declared in a different file...
extern or what?
common.h
file1.cpp
file2.cpp
The output is 32.

#ifndef COMMON_H#define COMMON_Hextern int common;void some_func();#endif
file1.cpp
#include "common.h"int common; //this line can appear in any cpp fileint main(){ common = 32; some_func(); return 0;}
file2.cpp
#include "common.h"void some_func(){ cout << common << endl;}
The output is 32.

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement