Overload constructors in VBScript

后端 未结 4 1934
逝去的感伤
逝去的感伤 2021-01-31 21:13

I found a way to extend classes in VBScript, but are there any ways to pass in parameters or overload the constructor? I am currently using an Init function to initialize the p

4条回答
  •  别那么骄傲
    2021-01-31 21:39

    A bit hackish, for sure, but when I need varargs in calls, one of my parameters I pass in as an array, i.e.

    Rem printf done poorly
    sub printf(fmt, args)
      dim fp, vap:
      dim outs:
      dim fini:
          fini = 0:
          vap = 0:
      while (not fini)
        fp = index(fmt,"%"):
        if (not(isNull(fp))) then
            ' do something with %f, %s
            select case(fp)
            case 'c':
              outs = outs & charparse(args(vap)):
            case 's':
              outs = outs & args(vap):
            ' and so on.  Quite incomplete but you get the idea.
            end select
            vap = vap + 1
        end if
      wend
    end sub
    
    printf("%s %d\n",array("Hello World", 42)):
    

提交回复
热议问题