Skip to main content
gamedev.net
🔒 Locked

Universal Project Scope

Started by Ratterbox 2 replies 300+ views
Original Post
Ratterbox
Ratterbox
Hi, I am using Microsoft Visual C++ 6, and was wondering if it is possible to have a piece of code containing data that is universal to all of the .CPP files in the project, Currently I am stuck with separate pieces of data, but i want it shared. Thanks in adavnce - Ratterbox
Narcist
Narcist
put it in a header (.h) file

#include that header file in each .cpp file

eg

#include "myheader.h"

at the top of every .cpp file
Ratterbox
Ratterbox
I already have a header file

The problem is, is that the header file contains a std::list
and there are different sets of data for every .CPP file that includes the header, I want there to be 1 list for multiple .CPP files
dcosborn
dcosborn
Use the extern keyword.

MyList.hpp

#include <list>
// Makes the variable visible to whoever includes the header.
extern std::list myList;

MyList.cpp

#include "MyList.hpp"
// Here's the declaration of our variable - it exists within
// MyList.cpp, but its accessible using extern.
std::list myList;


[edited by - dcosborn on November 25, 2003 5:40:22 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.