[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Class methods in GOOPS
From: |
Andreas Rottmann |
Subject: |
Re: Class methods in GOOPS |
Date: |
Sun, 12 Oct 2003 14:16:26 +0200 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) |
Andy Wingo <address@hidden> writes:
> Hello,
>
> It seems there are no class methods in GOOPS. Is this a deliberate
> omission, or were they just overlooked? If this is old hat, please point
> me to a URL somewhere, I couldn't find any.
>
What I did to work around this was to make the classes that should
have "class methods" (static methods in C++) have a metaclass, then
you can specialize methods on the metaclass; e.g:
(use-modules (oop goops))
(define-class <A-meta> ())
(define-class <B-meta> ())
(define-class <A> ()
#:metaclass <A-meta>)
(define-class <B> ()
#:metaclass <B-meta>)
(define-method (class-method (class <A-meta>) (msg <string>))
(format #t "I am a static method of class A: ~S\n" msg))
(define-method (class-method (class <B-meta>) (msg <string>))
(format #t "I am a static method of class B: ~S\n" msg))
(class-method <A> "Hello world")
(class-method <B> "Hello world")
> Thanks for any insight,
>
HTH, Andy.
Regards, Andy
--
Andreas Rottmann | address@hidden | address@hidden | address@hidden
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
Latein ist das humanoide Äquivalent zu Fortran.
-- Alexander Bartolich in at.linux