zoukankan      html  css  js  c++  java
  • Legacy:Within

    Legacy:Within

    From Unreal Wiki, The Unreal Engine Documentation Site

    Jump to: navigation, search

    The within UnrealScript keyword is used to forward class member access to another containing class. The PlayerInput class is an example of this keyword used in UT2003.

    You do not need to explicitly declare within for subclasses. That is, if class A is within class B, all subclasses of A will also be within class B.

    Example

    //
    // foo.uc
    //
     
    class Foo extends Object within Bar
     
    function DoSomething()
    {
      // This is a member of the Bar class.
      ++count;   
    }
     
     
    //
    // bar.uc
    //
     
    class Bar extends Object
     
    var int count;
    var Foo MyFoo;
     
    function DoSomethingElse()
    {
      count = 0;
      MyFoo.DoSomething();
      assert( count == 1 );
    }
    

    Foxpaw: How does this work WRT the instantiation of an object within another object? That is to say, how does Foo determine what instance of Bar it is "within?" It is simply by virtue of having the Foo variable in Bar? What happens if more than one instance of an object has a reference to the same Foo? What happens if you try to access properties of a Bar object from within the Foo object, but no Bar objects contain any references to Foos?

    El Muerte: within is mostly a hint for the compiler (to resolve variables and functions). Foo can only be a child of a single Bar. The owner of Foo has to be of type Bar and the Bar functions and variables accessed are called on the owner.

    Foxpaw: So, within gives the same effect as prepending "Bar(Owner)." to all of the properties of Bar?

    Wormbo: More like "Bar(Outer).", since we are talking about non-Actor objects here. I've noticed, though, that this only applies to variables. Functions still seem to require "Outer.", but it doesn't need to be typecasted to Bar because the Within keyword already states that there can't be any other Outer class.

  • 相关阅读:
    一个小厂算法工程师的2021个人年终总结
    优达学城 UdaCity 纳米学位
    Eclipse 常用可视化开发插件
    Android创建文件夹和文件
    Windows Mobile 播放声音文件
    C++实现顺序栈类
    c++实现的图类
    常见的字符串操作
    常见的链表操作
    取余数法实现哈希表(包括开放定址法和链地址法解决冲突)
  • 原文地址:https://www.cnblogs.com/Zephyroal/p/2367739.html
Copyright © 2011-2022 走看看