Calling a static function from a class member method is givinglinking errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Omar.Khalid79@gmail.com

    #1

    Calling a static function from a class member method is givinglinking errors

    Hi Guys,

    Maybe this is silly thing to ask but I have a static function declared

    static void Foo(int a);

    defined in Foo.cpp

    and a member method which calls Foo

    extern void foo(int a);
    void A::Test
    {
    int a = 0;
    foo(a);
    }

    I get linkage errors - 'un-resolved external symbol'. When I change
    Foo to non-static, it works. Any ideas?
  • David Wilkinson

    #2
    Re: Calling a static function from a class member method is givinglinking errors

    Omar.Khalid79@g mail.com wrote:
    Hi Guys,
    >
    Maybe this is silly thing to ask but I have a static function declared
    >
    static void Foo(int a);
    >
    defined in Foo.cpp
    >
    and a member method which calls Foo
    >
    extern void foo(int a);
    void A::Test
    {
    int a = 0;
    foo(a);
    }
    >
    I get linkage errors - 'un-resolved external symbol'. When I change
    Foo to non-static, it works. Any ideas?
    Omar:

    Because, in this context, static means "to be used only in this translation
    unit". This use of the static keyword is deprecated in C++; use unnamed
    namespace instead.

    Also, you do not need extern here.

    --
    David Wilkinson
    Visual C++ MVP

    Comment

    • Omar.Khalid79@gmail.com

      #3
      Re: Calling a static function from a class member method is givinglinking errors

      On Mar 20, 1:16 pm, David Wilkinson <no-re...@effisols. comwrote:
      Omar.Khali...@g mail.com wrote:
      Hi Guys,
      >
      Maybe this is silly thing to ask but I have a static function declared
      >
      static void Foo(int a);
      >
      defined in Foo.cpp
      >
      and a member method which calls Foo
      >
      extern void foo(int a);
      void A::Test
      {
        int a = 0;
        foo(a);
      }
      >
      I get linkage errors - 'un-resolved external symbol'. When I change
      Foo to non-static, it works. Any ideas?
      >
      Omar:
      >
      Because, in this context, static means "to be used only in this translation
      unit". This use of the static keyword is deprecated in C++; use unnamed
      namespace instead.
      >
      Also, you do not need extern here.
      >
      --
      David Wilkinson
      Visual C++ MVP- Hide quoted text -
      >
      - Show quoted text -
      Thanks David!!!

      Comment

      Working...