C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-02-2008, 08:24 AM   #1
Registered User
 
Swarvy's Avatar
 
Join Date: Apr 2008
Location: United Kingdom
Posts: 80
Working with muliple source files

I was wondering about working with mulitple source files. In the project that I'm working on at the moment, I have several header files and several cpp files. The only problem is that in one or two of the classes (which are in separate header files), there are a few methods I made which take the a handle to the window (really its a HWND handle, but in the example below I used a HANDLE handle), I was wondering if there is any way of making a variable visible to just a few header files? I've heard of the extern keyword being used for something similar to that, but never used it. Is there a better way to do it than just declare it as a global variable and make it visible to all source code files? Is there any way to pass source code files arguments, like functions and methods, so if I passed an argument to example.h then that would be like a global variable declaration in example.h?

Code:
<---- Position (2) - See comment below
#include "example.h"

EXAMPLE1 Example1;

int main(int argc, char *argv[])
{
         HANDLE hOut;
         Example1.func1(hOut);
         return 0;
}
In the example above, I have methods in EXAMPLE1, which take hOut as a parameter, but I wanna keep hOut local, but if I do that, I have problems with the way the methods are defined in example1.h

Also, even if I declare it at position (2) in the code, it isn't visible to example1.h, how do you think I should solve these problems?
Swarvy is offline   Reply With Quote
Old 10-02-2008, 08:36 AM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 11,338
Quote:
In the example above, I have methods in EXAMPLE1, which take hOut as a parameter, but I wanna keep hOut local, but if I do that, I have problems with the way the methods are defined in example1.h
What kind of problems do you have?
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
working with compressed files tonyjeffs C Programming 4 10-02-2007 11:59 AM
Threads to keep the CPU faster than the disk? matthew180 C Programming 4 06-06-2007 03:23 PM
Linker errors - Multiple Source files nkhambal C Programming 3 04-24-2005 02:41 AM
Major glitch losing source files with MSVC++ and WinXP JasonD C++ Programming 10 08-14-2003 12:15 PM
using a class in multiple source files??? Crossbow C++ Programming 9 06-18-2002 07:42 PM


All times are GMT -6. The time now is 11:55 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22