Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • type mismatch error in declaring a function of a class

    Dear Statalist,

    I have one question regarding the mata programming. I couldn't figure out why mata reports an error "type mismatch: exp.exp: transmorphic found where struct expected" when it goes to codes
    Code:
    AA.aa = sum(A1.a)
    for function -myfct2-.

    Kind regards,
    Yugen

    Code:
    mata:
    
    mata clear
    
    //-------------------------------------------------
    class Myclass1 {    
        
        real vector a
        
    }
    
    class Myclass1 scalar myfct1 (real vector b)  {
        
        class Myclass1 scalar A
    
        A.a = b
    
        return(A)
    }
    
    //-------------------------------------------------
    
    class Myclass2  {
    
        real scalar aa
    
    }
    
    class Myclass2 scalar myfct2 (real vector b)  {
        
        class Myclass2 scalar AA
        
        A1=myfct1(b)
        
        AA.aa = sum(A1.a)
        
        return(AA)
        
        
    }
    
    
    end
    Last edited by Yugen Chen; 30 Jul 2022, 18:01.

  • #2
    Try this.
    Code:
    version 17.0
    
    clear *
    
    mata:
    mata set matastrict on
    
    //-------------------------------------------------
    class Myclass1 {    
        
        real vector a
        
    }
    
    class Myclass1 scalar myfct1 (real vector b)  {
        
        class Myclass1 scalar A
    
        A.a = b
    
        return(A)
    }
    
    //-------------------------------------------------
    
    class Myclass2  {
    
        real scalar aa
    
    }
    
    class Myclass2 scalar myfct2 (real vector b)  {
        
        class Myclass2 scalar AA
    class Myclass1 scalar A1
        A1=myfct1(b)
    
        AA.aa = sum(A1.a)
        
        return(AA)
        
        
    }
    
    AnAA = myfct2((2, 2))
    AnAA.aa
    
    end
    
    exit

    Comment


    • #3
      That works. Joseph, thanks very much!

      Comment

      Working...
      X