GLBasic forum

Main forum => GLBasic - en => Topic started by: bigsofty on 2007-Apr-05

Title: error: invalid initialization of non-const reference of type
Post by: bigsofty on 2007-Apr-05
Code (glbasic) Select
TYPE Tvector
x
y
z
magnitude
ENDTYPE

FUNCTION vector_new AS Tvector: x,y,z,m
LOCAL result AS Tvector
result.x=x
result.y=y
result.z=z
result.magnitude=m
RETURN result
ENDFUNCTION

FUNCTION add_to_particles_array: a, b, vec AS Tvector
ENDFUNCTION

FUNCTION testf:
add_to_particles_array(1, 1, vector_new(100,100,0,0))
ENDFUNCTION
produces this error...

Code (glbasic) Select
_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2007.083 - 3D, NET
Wordcount:8 commands

compiling:
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp0.cpp: In function `DGInt __GLBASIC__::testf()':
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp0.cpp:35: error: invalid initialization of non-const reference of type '__GLBASIC__::Tvector&' from a temporary of type '__GLBASIC__::Tvector'
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp0.cpp:29: error: in passing argument 3 of `DGInt __GLBASIC__::add_to_particles_array(DGInt, DGInt, __GLBASIC__::Tvector&)'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Time: 0.8 sec
Build: 0 succeeded
*** 1 FAILED ***
This is a small section of offending code I've tried to cut out of my own program... I must be doing this wrong?

:s
Title: error: invalid initialization of non-const reference of type
Post by: Lazarus on 2007-Apr-05
Why is there no code in the add_to_particles_array function?
Title: error: invalid initialization of non-const reference of type
Post by: Kitty Hello on 2007-Apr-05
it's returning a TYPE by reference. That's bad in your case, faster in most others. I'll have to fix it.
So far, make a LOCAL for the return value of add_to_particle_array, and pass this to the function.
Title: error: invalid initialization of non-const reference of type
Post by: bigsofty on 2007-Apr-05
Because it irrelevant to the error I'm afraid.

Code there or not, the error revolves around functions returning types in this situation.
Title: error: invalid initialization of non-const reference of type
Post by: bigsofty on 2007-Apr-05
Quote from: GernotFrischit's returning a TYPE by reference. That's bad in your case, faster in most others. I'll have to fix it.
So far, make a LOCAL for the return value of add_to_particle_array, and pass this to the function.
:( OK, Ill add, add that bit of code for now Gernot, thanks for looking into it.
Title: error: invalid initialization of non-const reference of type
Post by: Kitty Hello on 2007-Apr-07
Oh dear. I'm not sure if I can get this working at all. That would require a whole lot of work. However, you get a better error message now.
Title: error: invalid initialization of non-const reference of type
Post by: bigsofty on 2007-Apr-07
OK Gernot, thanks for giving it a go and its easy to work around.

Now get to bed its late! :P