Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: In Mata: Referring to an instance of a class inside an external function?

From   YutaoSun <>
To   "" <>
Subject   st: In Mata: Referring to an instance of a class inside an external function?
Date   Fri, 5 Apr 2013 14:38:39 +0200

Dear users,

I have a tricky question about OOP in Mata. Here is the thing, I have written a class (let's call it "C"), and several EXTERNAL functions. sometimes In the external functions, I need to refer to the instance of "C".

I tried This: I put a pointer (let's call it "P") as a member variable of the class and it always points to -&this- and I send the pointer into the external function that needs to refer to the class. When I type "P" in the external function, it gives an address (of course because it's a pointer) and this address is exactly the same as what shows up on the screen when I type "P" in a method of "C". However, when I realize the pointer (i.e. use -(*P)-) inside the external function, it gives "0x0" which I believe is a pointer to "NULL". Here is my code (a piece of pesudo code because the actual situation is a lot complicated than what I explained here).

// start class definition
class SomeClass {
    pointer scalar P

    void new()
    void ShowPointer()
void function SomeClass::new() {
void function SomeClass::ShowPointer() {
void function SomeClass::CallExternalFunction() {
// external function definition
void function AnExternalFunction(pointer scalar Pointer) {
// an instance
// **** this prints out:
// **** an address
// **** "class"
// **** this prints out:
// **** the same address
// **** "pointer"

Does anyone possibly know what's wrong and how to make this happen, or there is a protective machanism going on in Mata? 		 	   		  
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index