Advertisement

use same int in different files

Started by December 10, 2003 04:03 PM
1 comment, last by dennizzz 21 years, 2 months ago
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

#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
Advertisement
oki... thanx it works fine..

but when i shift scene now the text that displays looks
messed up... it blinks ?

This topic is closed to new replies.

Advertisement