Inline variable access problem

Previous topic - Next topic

MrTAToad

With the following :

Code (glbasic) Select
CONSTANT PTR_BCONTAINER% = -1
CONSTANT PTR_CONTAINER% = 0
CONSTANT PTR_WINDOW% = 1

INLINE
switch (ptrType) {
case PTR_BCONTAINER :
container->add(label,x,y);
break;

case PTR_WINDOW :
{
gcn::Window *win;

win=(gcn::Window *) ptr;
win->add(label,x,y);
}
break;

case PTR_CONTAINER:
{
gcn::Container *container;

container=(gcn::Container *) ptr;
container->add(label,x,y);
}
break;
};
ENDINLINE


I get the following error :

C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGNat __GLBASIC__::GUI_CreateLabel(DGNat, DGNat, DGNat, __GLBASIC__::DGStr, DGNat)':
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp1.cpp:670: error: `__GLBASIC__::PTR_BCONTAINER' cannot appear in a constant-expression

It appears that putting -1 in brackets (-1) doesn't solve the problem :

Code (glbasic) Select
CONSTANT PTR_BCONTAINER% = (-1)

MrTAToad

It is also fine is if "if" statements are used instead of switch...

Kitty Hello

ah, no. The GLBasic CONSTANT does _not_ make a const int in C++. If you want that, you must define it explicitly in inline.

MrTAToad

Ah, right - strange it was working with some variables though...