Thread: namespace question

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

    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?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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,708
    Thanks Prelude!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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, 09:22 PM
  5. using namespace std; question.
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 12-30-2002, 04:39 PM