Thread: namespace in diffrent file

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    namespace in diffrent file

    I have created another file names abs.hpp where I have defined a namespace ns, I have inserted the using namespace ns; code is my main.cpp
    when i run it it says ‘ns’ is not a namespace-name, do I need to include abs.hpp?
    if so how?


    what are the other things I need to keep in my mind?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, you need to include the header. The compiler must be able to see the namespace.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    134

    how to include the header?

    let the file is adt.hpp

    Code:
    #include "adt.cpp"
    will do?

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    134
    I am getting this error
    what does it mean and how to solve it?

    rectangle.cpp:276: error: call of overloaded ‘interList(absDataTypes::rectNode*&)’ is ambiguous

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, you include the header. Make sure you have appropriate prototypes in your header and your implementations in the source file.
    The error means that you have several functions with the same name and you're trying to call one, but the compiler is confused about which one you meant to call (it couldn't figure it out).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    134
    is it the correct method of including?

    Code:
    #include "adt.hpp"
    ?

    I have written the function prototype in header file and implemented it in the main.cpp file, there is no other function named after the same name, may be something other is happening.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That is correct.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 04:24 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM