BYREF + TYPE in FUNCTION

Previous topic - Next topic

9940

How can i get this code works ?

Code (glbasic) Select

TYPE CMAP
NAME$
BACKGROUND
MAP[20][15]
ENDTYPE

FUNCTION MAP_LOAD: filename$, BYREF pMAP AS CMAP
pMAP.NAME$ = "A"
ENDFUNCTION



compiling:
In file included from C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_tempg.cpp:2:
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp.h:8: error: `Anything' has not been declared
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp.h:8: error: ISO C++ forbids declaration of `pMAP' with no type
In file included from C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp0.cpp:1:
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp.h:8: error: `Anything' has not been declared
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp.h:8: error: ISO C++ forbids declaration of `pMAP' with no type
In file included from C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp1.cpp:1:
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp.h:8: error: `Anything' has not been declared
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp.h:8: error: ISO C++ forbids declaration of `pMAP' with no type
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp1.cpp:5: error: `Anything' has not been declared
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp1.cpp:6: error: ISO C++ forbids declaration of `pMAP' with no type
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::MAP_LOAD(__GLBASIC__::DGStr, int)':
C:\DOCUME~1\User\IMPOST~1\Temp\glbasic\gpc_temp1.cpp:8: error: request for member `NAME_Str' in `pMAP', which is of non-class type `int'

MrTAToad

Try this out :

Code (glbasic) Select
TYPE CMAP
NAME$
BACKGROUND
MAP[20][15]
ENDTYPE

GLOBAL test AS CMAP

test.NAME$="TEST"
DEBUG "Before Function : "+test.NAME$+"\n"
MAP_LOAD("Z",test)
DEBUG "After Function : "+test.NAME$+"\n"
END


FUNCTION MAP_LOAD: filename$, pMAP AS CMAP
pMAP.NAME$ = "A"
ENDFUNCTION


BYREF doesn't need to be used when TYPE's are passed.

Hemlos

#2
Correct me if im wrong, MAP cant be passed as byref, because its a type not a variable.
SO you can pass a byref variable into the type.
This works:


Code (glbasic) Select

TYPE CMAP
NAME$
BACKGROUND
MAP[20][15]
ENDTYPE


FUNCTION MAP_LOAD: BYREF NAME$, MAP AS CMAP
MAP.NAME$ = NAME$
ENDFUNCTION


One other thing.....dont use all capital letters in any declarations.
GLBasic uses all capital case variables, and you may find interference here.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

9940