Hi
According to the code below it seems like you can not use classes as arguments to or inside functions.
Is that true? Or am I doing something wrong?
If it is true is there then a workaround for it?
According to the code below it seems like you can not use classes as arguments to or inside functions.
Is that true? Or am I doing something wrong?
If it is true is there then a workaround for it?
Code:
cls
mata
mata clear
class coord {
real scalar x, y
real scalar length(), angle()
}
real scalar coord::length()
{
return(sqrt(x^2 + y^2))
}
real scalar coord::angle()
{
return(atan2(y, x)*360/(2*pi()))
}
void test1(class coord scalar c)
{
return(c.length())
}
void test2(real scalar x, y)
{
real scalar l
class coord scalar c
c = coord()
c.x = x
c.y = y
l = c.length()
return(l)
}
c = coord()
c.x = 4
c.y = 3
c.length()
test1(c)
/* From the Results window
: test1(c)
test1(): 3258 l[1,1] found where void required
<istmt>: - function returned error
r(3258);
*/
test2(5, 12)
/* From the Results window
: test2(5, 12)
test2(): 3258 l[1,1] found where void required
<istmt>: - function returned error
r(3258);
*/
end

, also:
Comment