🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.objective-c
Article #425

Can't see variable

#425
From: George Farris
Date: Sun, 14 Feb 1999 00:00
82 lines
2290 bytes
I'm trying to learn Objective-C and am confused about the 
inheritance of instance variables.  In the following code
"Parent" has a variable called "name".  "Child" is a subclass
of "Parent".  From reading information on Obj-C I understood that
the "Child" would be able to see "name", it doesn't.

The manual I have on Obj-C says: "When a class object creates a
new instance, the object contains not only the instance variables
that were defined for its class, but also instance variables
defined for its superclass, and for its superclass's superclass,
all the way back to the root class."

If I declare a new variable in "Child" called "name", I get an error
saying it's overriding an existing instance variable.  Can 
someone please clear this up for me.


#include <objc/Object.h>

@interface Parent : Object
{
        char name[20];  
}
-init:(char *)app_id :(int) argc :(char **) argv;
-print;

@end


@interface Child : Parent 
{
}
-init;

@end

@implementation Parent
-init:(char *)app_id :(int) argc :(char **) argv
{
        [super init];

        strcpy(name, "Hello, World\n");

        printf("In Parent name is ->%s\n", name);
}

-print
{
        id child;

        child = [[Child alloc] init];
        return self;
}

@end


@implementation Child
-init
{
        printf("In Child name is ->%s\n", name);
        return self;
}

@end

int main(int argc, char *argv[])
{

        id myapp;

        myapp = [Parent alloc];
        [myapp init:"Test" :argc :argv];
        [myapp print];

        return 0;

}

-- 
=====================================================================
George Farris - VE7FRG           E-Mail : george@gmsys.com
Technical Details
Message-ID: <7a78io$vv$1@ve7frg.gmsys.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10e5ed,472bd2bca027a261,start
X-Google-Attributes: gid10e5ed,public
X-Google-Thread: 1111a3,472bd2bca027a261,start
X-Google-Attributes: gid1111a3,public
From: george@gmsys.com (George Farris)
Subject: Can't see variable
Date: 1999/02/14
Message-ID: <7a78io$vv$1@ve7frg.gmsys.com>
X-Deja-AN: 444355711
Sender: george@ve7frg.gmsys.com
Organization: (G.M. Systems)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: comp.lang.objective-c,gnu.gnustep.discuss