www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Calling base class function

reply Joshua Cearley <jtech ezoob.com> writes:
How would I accomplish this? I tried using the super() command (as you 
can in Ruby) but it apparently is only for constructors? Any input would 
be welcomed.

I think the Super command should accomplish this, it works in Ruby, and 
it lets you do this kind of thing.

What my system does is when you say SaveToStream to a Cardboard Box it 
would save its class name and signature version, then do the same for 
the class above it until it hits the top, then they start saving their 
data. The output would look something like this:

CardboardBox 1 Box 1 StorageUnit 1 <StorageUnit data> <Box data> 
<CardboardBox data>

(or in hierarchial form)
CardboardBox 1
  - Box 1
  | - StorageUnit 1
  | | - StorageUnit Data
  | - Box Data
  - CardboardBox Data

This lets you make sure that the serialization stream is supported 
before trying to read it in.

-JC
Apr 24 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joshua Cearley schrieb am Mon, 25 Apr 2005 00:56:45 -0500:
 How would I accomplish this? I tried using the super() command (as you 
 can in Ruby) but it apparently is only for constructors? Any input would 
 be welcomed.

 I think the Super command should accomplish this, it works in Ruby, and 
 it lets you do this kind of thing.
import std.stdio; class A{ int check(){ return 1; } } class B : A{ int check(){ return 2; } int test(){ return super.check(); } } int main(){ printf("%i\n", (new B()).test); return 0; } Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCbIiE3w+/yD4P9tIRAhCPAKDRdMQIZ6YUQ+maM/X+jrSQIGOPCQCgxQBq Ii3PN0x9ZSV+ALImWUZ1z28= =pCdt -----END PGP SIGNATURE-----
Apr 24 2005
parent reply Joshua Cearley <jtech ezoob.com> writes:
Thanks, I thought super was a function.

-JC
Apr 25 2005
parent Chris Sauls <ibisbasenji gmail.com> writes:
Joshua Cearley wrote:
 Thanks, I thought super was a function.
It can be used with either function or variable syntax, depending on where its used. Essentially, the function syntax 'super()' is only available within constructors, to specify where to perform the base class constructor and/or pass values to the base class constructor. The variable syntax 'super' is available anywhere within a class to refer to the base class as an identifier qualifier. -- Chris Sauls
Apr 25 2005