help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make a static function a friend of a class


From: Maett
Subject: Re: how to make a static function a friend of a class
Date: Mon, 16 May 2005 18:28:38 +0200
User-agent: Opera M2/7.54 (Win32, build 3929)

Larry I Smith wrote:
Maett wrote:
Hi.

I would like to access private class data out of a static function as
follows:

foo1.h:
  class foo1Class {
    public:
      static int getN();
    private:

         friend int ::foo1();
      // friend int foo1();
      static const int n;
  };

foo1.cpp:
  #include "foo1.h"

  const int foo1Class::n = 77;

  int foo1Class::getN()
  {
    return foo1();
  }


     int foo1()

But I would like foo1 to be static to avoid it being a global symbol.
(I have a tool which generates c++ code out of data structure definitions, and there are quite a few such definitions, which would lead to manymany global symbols. Unfortunately I am stuck to g++ 3.2.3 for the moment, so I can not use the
  __attribute__ ((visibility("hidden")))
mechanism of g++ 3.4 and later.)

  // static int foo1()
  {
    return foo1Class::n;
  }


Then g++ (3.2.3) tells me:
  foo1.cpp: In function `int foo1()':
  foo1.cpp:11: `int foo1()' was declared `extern' and later `static'
  foo1.h:5: previous declaration of `int foo1()'

Which of course is correct.

[snip]

Regards,
Larry


Is there a possibility with anonymous namespaces instead of "static" ?
I didn't succeed, either.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]