namespace question

This is a discussion on namespace question within the C++ Programming forums, part of the General Programming Boards category; I have a C++ class that has a function "Connect()" which calls another function I wrote in straight C, also ...

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,658

    namespace question

    I have a C++ class that has a function "Connect()" which calls another function I wrote in straight C, also called Connect.

    My question is, how can I call the second in the first without the names clashing?



    ITSA
    Socket Library!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    If the C function is a member of another namespace then all you have to do is use the scope resolution operator with the namespace:
    namespace :: Connect();

    If you aren't using namespaces and the function is global, then you can do something like this:
    Code:
    #include <iostream>
    using std::cout;
    
    void func ( void )
    {
      cout<<"global\n";
    }
    
    class test
    {
    public:
      void func ( void );
    };
    
    void test::func ( void )
    {
      cout<<"local to test\n";
      ::func(); // Global namespace
    }
    
    int main ( void )
    {
      test t;
      t.func();
      return 0;
    }
    This code will print

    local to test
    global

    -Prelude
    My best code is written with the delete key.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,658
    Thanks Prelude!



    ITSA
    Socket Library!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. namespace question
    By Dave++ in forum C++ Programming
    Replies: 6
    Last Post: 06-04-2007, 05:47 PM
  3. A fourth noobie question - namespace std?
    By Noobie in forum C++ Programming
    Replies: 24
    Last Post: 08-12-2005, 02:10 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  5. using namespace std; question.
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 12-30-2002, 03:39 PM

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