by NoWest » 2007年1月15日(月) 13:43
> 次のクラスを含むコードをコンパイルしようとすると
>
>
コード: 全て選択
> Class StrList
> Private
> dim pStr as *BytePtr
> dim nHasStr as long
> dim nShowed as long
> Public
> sub StrList()
> pStr=malloc(sizeof(Byte)*256)
> nHasStr=0
> nShowed=0
> end sub
>
> sub ~StrList()
> dim i as Long
> for i = 0 to nHasStr-1
> free(pStr)
> next i
> free(pStr)
> end sub
>
>
> function GetnHasStr() as Long
> GetnStr=nHasStr
> end function
>
> function PutStr(ss as BytePtr)as long
> dim q as *BytePtr
> dim i as Long
>
> if nHasStr>=2000000000 then
> PutStr=-1
> Exit Function
> elseif nHasStr mod 256 = 0 then
> q=pStr
> pStr=malloc(sizeof(Byte)*(nHasStr+256))
> for i=0 to nHasStr-1
> pStr=q
> next i
> End if
>
> pStr[nHasStr]=malloc(sizeof(Byte)*lstrlen(ss))
> lstrcpy(pStr[nHasStr],ss)
> nHasStr=nHasStr+1
> PutStr=nHasStr
> end function
>
> function GetStr(ss as BytePtr)as long
> if nShowed>=nHasStr then
> GetStr=-1
> else
> strcpy(ss,pStr[nShowed])
> GetStr=0
> end if
> end function
> end class
>
> 次のようなエラーが出ます
> コード: 全て選択
> MainWnd.sbp(16) - "pStr" 無効な識別子です
> MainWnd.sbp(17) - "nHasStr" 無効な識別子です
> MainWnd.sbp(18) - "nShowed" 無効な識別子です
> MainWnd.sbp(23) - "nHasStr" 無効な識別子です
> MainWnd.sbp(24) - "pStr" 無効な識別子です
> MainWnd.sbp(26) - "pStr" 無効な識別子です
> MainWnd.sbp(38) - "nHasStr" 無効な識別子です
> MainWnd.sbp(42) - "pStr" 無効な識別子です
> MainWnd.sbp(45) - "pStr" 無効な識別子です
> MainWnd.sbp(47) - "End If" の使い方が不正です
> MainWnd.sbp(49) - "pStr[nHasStr]" 無効な識別子です
>
>
> どこが間違っているのかわかりません
> どなたか教えてください
こんにちは
この板に書き込むのはかなり久しぶりのNoWestです。
Class StrList
Private
dim pStr as *BytePtr
dim nHasStr as long
dim nShowed as long
~以下略~
クラス内においては基本的にメソッド内で定義する変数以外、即ちメンバ変数にはDimは必要ありません。
ようするに構造体と同じです。
> 次のクラスを含むコードをコンパイルしようとすると
>
> [code]
> Class StrList
> Private
> dim pStr as *BytePtr
> dim nHasStr as long
> dim nShowed as long
> Public
> sub StrList()
> pStr=malloc(sizeof(Byte)*256)
> nHasStr=0
> nShowed=0
> end sub
>
> sub ~StrList()
> dim i as Long
> for i = 0 to nHasStr-1
> free(pStr[i])
> next i
> free(pStr)
> end sub
>
>
> function GetnHasStr() as Long
> GetnStr=nHasStr
> end function
>
> function PutStr(ss as BytePtr)as long
> dim q as *BytePtr
> dim i as Long
>
> if nHasStr>=2000000000 then
> PutStr=-1
> Exit Function
> elseif nHasStr mod 256 = 0 then
> q=pStr
> pStr=malloc(sizeof(Byte)*(nHasStr+256))
> for i=0 to nHasStr-1
> pStr[i]=q[i]
> next i
> End if
>
> pStr[nHasStr]=malloc(sizeof(Byte)*lstrlen(ss))
> lstrcpy(pStr[nHasStr],ss)
> nHasStr=nHasStr+1
> PutStr=nHasStr
> end function
>
> function GetStr(ss as BytePtr)as long
> if nShowed>=nHasStr then
> GetStr=-1
> else
> strcpy(ss,pStr[nShowed])
> GetStr=0
> end if
> end function
> end class
> [/code]
> 次のようなエラーが出ます
> [code]
> MainWnd.sbp(16) - "pStr" 無効な識別子です
> MainWnd.sbp(17) - "nHasStr" 無効な識別子です
> MainWnd.sbp(18) - "nShowed" 無効な識別子です
> MainWnd.sbp(23) - "nHasStr" 無効な識別子です
> MainWnd.sbp(24) - "pStr[i]" 無効な識別子です
> MainWnd.sbp(26) - "pStr" 無効な識別子です
> MainWnd.sbp(38) - "nHasStr" 無効な識別子です
> MainWnd.sbp(42) - "pStr" 無効な識別子です
> MainWnd.sbp(45) - "pStr[i]" 無効な識別子です
> MainWnd.sbp(47) - "End If" の使い方が不正です
> MainWnd.sbp(49) - "pStr[nHasStr]" 無効な識別子です
> [/code]
>
> どこが間違っているのかわかりません
> どなたか教えてください
こんにちは
この板に書き込むのはかなり久しぶりのNoWestです。
Class StrList
Private
dim pStr as *BytePtr
dim nHasStr as long
dim nShowed as long
~以下略~
クラス内においては基本的にメソッド内で定義する変数以外、即ちメンバ変数にはDimは必要ありません。
ようするに構造体と同じです。