どこが間違っているのでしょうか?

返信する


答えを正確に入力してください。答えられるかどうかでスパムボットか否かを判定します。

BBCode: ON
[img]: ON
[url]: ON
スマイリー: OFF

トピックのレビュー
   

展開ビュー トピックのレビュー: どこが間違っているのでしょうか?

解決しました

by doloop » 2007年1月15日(月) 14:24

NoWestさん、すばやいを回答ありがとうございます
問題は解決しました

Re: どこが間違っているのでしょうか?

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は必要ありません。

ようするに構造体と同じです。

どこが間違っているのでしょうか?

by doloop » 2007年1月15日(月) 13:03

次のクラスを含むコードをコンパイルしようとすると

コード: 全て選択


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]" 無効な識別子です


どこが間違っているのかわかりません
どなたか教えてください

ページトップ