Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Using transmorphic variables to hold objects in Mata


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: Using transmorphic variables to hold objects in Mata
Date   Tue, 28 May 2013 01:10:15 +0900

It seems that the pointer two-step doesn't really get around the problem,
either.  The pointer doesn't really recognize the other object's type, and Mata
doesn't detect (balk) when it's pointed to an object of a different type.

Joseph Coveney


. version 12.1

. 
. clear *

. set more off

. 
. mata:
------------------------------------------------- mata (type end to exit)
----------------------------------------------------------------
: mata set matastrict on

: 
: class A {
>         public:
>                 static final void show()
> }

: void function A::show() printf("A\n")

: 
: class IsNotAnA {
>         public:
>                 static final void show()
> }

: void function IsNotAnA::show() printf("NotA\n")

: 
: class B {
>         public:
>                 static final void test()
> }

: void function B::test(transmorphic scalar is_an_a) {
>         pointer(class IsNotAnA scalar) scalar not_an_a_ptr
>         not_an_a_ptr = NULL
>         not_an_a_ptr = &is_an_a
>         not_an_a_ptr->show()
> }

: 
: void function test() {
>         class B scalar b
>         b.test(A())
> }

: 
: test()
NotA

: 
: end
--------------------------------------------------------------------------------
----------------------------------------------------------

. 
. exit

end of do-file

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index