Thread: Working with muliple source files

  1. #1
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195

    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?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

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