namespaces in multiple files

This is a discussion on namespaces in multiple files within the C++ Programming forums, part of the General Programming Boards category; if i define a namespace in file 1, and #include file 1 in file 2, how do i access the ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    2

    Question namespaces in multiple files

    if i define a namespace in file 1, and #include file 1 in file 2, how do i access the namespace in file 3... when you would use extern if it were a normal variable.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,442
    hmm... why not just include file 1 in file 3?
    If you have header guards in file 1 there should not be a problem.

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    2
    Originally posted by laserlight
    hmm... why not just include file 1 in file 3?
    If you have header guards in file 1 there should not be a problem.
    i tried that but i get a linker error saying that a variable is already defined.

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    Originally posted by laserlight
    hmm... why not just include file 1 in file 3?
    If you have header guards in file 1 there should not be a problem.
    What header guards means is in your header header.h add
    Code:
    #ifndef HEADER_INCLUDED
    #define HEADER_INCLUDED
    -- the header file
    #endif
    This way the header content will be included only once.

    Originally posted by olsmokey
    i tried that but i get a linker error saying that a variable is already defined.
    Your header file should not define any variables. Only define vars in the C/CPP files.

    If a variable needs to be available in more than one C file, the header can specify the variable as extern. It will then be available to all modules.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opening Multiple Files in sequence
    By wujiajun in forum C++ Programming
    Replies: 7
    Last Post: 01-16-2006, 07:47 PM
  2. Replies: 4
    Last Post: 06-18-2005, 02:26 PM
  3. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  4. copy multiple files to a destination file
    By Bones in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2003, 10:47 AM
  5. opening multiple files sequentially
    By moonwalker in forum C Programming
    Replies: 5
    Last Post: 08-20-2002, 09:57 PM

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