This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: __attribute__ vs c++


nbecker@fred.net wrote:
> 
> egcs-1.1a i686-pc-linux-gnu.
> 
> bug.cc:
> class A {
>   const int x;
>   int X () const __attribute__((const)) {
>     return x;
>   }
> };
> 
> gcc -c bug.cc
> bug.cc:3: parse error before `{'
> 
> Is __attribute__ not usable for methods?

Try treating the __attribute__ as a type modifier. ie:

...
int __attribute__((const)) X () const {
  return x;
}
...

This is how you do this in C.  __attribute__ can be used with methods in
C++; I have (gcc 2.7.2.1) but the definition of the method was separate
from the class definition (inlining was inappropriate).

Bill
-- 
Leave others their otherness


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]