找回密码
 点一下
查看: 1680|回复: 3

结构的构造函数问题

[复制链接]
发表于 2009-10-22 22:09:47 | 显示全部楼层 |阅读模式
[jass]
library A  //错误代码(命名为"代码1")
  globals
     B array test
  endglobals
  struct B
     public integer a
     public integer b
    
     method ab takes integer a1 , integer b1 returns nothing
         set this.a = a1
         set this.b = b1
         call BJDebugMsg(I2S(this.a))
         call BJDebugMsg(I2S(this.b))
     endmethod
    
     method create takes nothing returns nothing
       call DisplayTextToPlayer(Player(0),0,0,"111")
     endmethod
  endsturct
endlibrary

function go takes nothing returns nothing
  set test[1] = B.craete()
  call test[1].ab(10,20)
endfunction
[/jass]

[jass]
library A  //正确代码(命名为"代码2")
  globals
     B array test
  endglobals
  struct B
     public integer a
     public integer b
    
     method ab takes integer a1 , integer b1 returns nothing
         set this.a = a1
         set this.b = b1
         call BJDebugMsg(I2S(this.a))
         call BJDebugMsg(I2S(this.b))
     endmethod
    
     method create takes nothing returns nothing
     endmethod
  endsturct
endlibrary

function go takes nothing returns nothing
  set test[1] = B.craete()
  call test[1].ab(10,20)
endfunction
[/jass]

请问...为什么 构造函数 create() 加一条函数 就会是错误的 不加就没问题呢- -....
请说明一下 构造函数吧...谢谢
发表于 2009-10-22 22:24:38 | 显示全部楼层
你这样写create函数就不对。
应该是static method create takes something returns thistype
请注意create和Destroy、destroy这样的函数规范处理。
而不是去找无所谓的VJBug。
回复

使用道具 举报

发表于 2009-11-30 12:34:40 | 显示全部楼层
VJ - -
VJ

我总觉得如果不把J搞透彻最好不要接触VJ

这就像是没学C直接搞C++一样。。
回复

使用道具 举报

发表于 2009-11-30 12:46:10 | 显示全部楼层
我非常多年前就一直很讨厌面向对象的写法并且不能理解

现在理解了以后发现还是很讨厌,面向对象的写法仅仅当你声明了一个函数绑定的存储空间时有意义
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-4-27 19:05 , Processed in 0.117472 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表