Author Topic: BYREF + TYPE in FUNCTION  (Read 2250 times)

9940

  • Guest
BYREF + TYPE in FUNCTION
« on: 2009-Jul-19 »
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

  • Guest
Re: BYREF + TYPE in FUNCTION
« Reply #1 on: 2009-Jul-19 »
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.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1621
  • Particle Hawk
    • View Profile
Re: BYREF + TYPE in FUNCTION
« Reply #2 on: 2009-Jul-19 »
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.
« Last Edit: 2009-Jul-19 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

9940

  • Guest
Re: BYREF + TYPE in FUNCTION
« Reply #3 on: 2009-Jul-19 »
 :good: Thx all