[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: class/subclass ivars
From: |
David Chisnall |
Subject: |
Re: class/subclass ivars |
Date: |
Mon, 11 Jan 2016 15:26:31 +0000 |
If the ivars are declared in the @interface, then they are visible to all
subclasses and you will get an error if the names match ones declared in
subclasses. If the ivars are declared in the @implementation context, then you
will get no error and each class will refer to its own private version. This
gets a bit complicated when you refer to the ivars by name in introspection
(you’ll likely see confusing things if you tell KVC to directly access ivars,
for example).
David
> On 11 Jan 2016, at 15:16, Riccardo Mottola <address@hidden> wrote:
>
> Hi,
>
> I have a simple question and I am unsure about the answer.
>
> Suppose we have class A with an ivar _var.
>
> Now, I subclass A with B. Since I don't know the declaration of A, I also
> need an ivar and call it _var and they probably have the same type.
>
> What happens? Do I get a compiler error? Does the compiler smartly renames
> the two variables like _var_A and _var_B? Does the second declaration get
> ignored and the code refers to the same variable? I would expect the
> renaming behaviour, but the latter also makes
>
> I wonder if there is risk calling vars like "_size" or "width" "height" which
> have common names enough to be declared up in the hierarchy.
> I am debugging code that works on Mac and not on GS, so I got the doubt.
>
> Riccardo
>
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/gnustep-dev
--
This email complies with ISO 3103