[solved] error 67 ?

General FreeBASIC programming questions.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

[solved] error 67 ?

Post by D.J.Peters »

The overloaded max function for the real and v2 is ok but for v3 it produce the error:
error 67: Too many expressions, found 'iif' in 'return type<v3>( iif(a.x>b,a.x,b), iif(a.y>b,a.y,b), iif(a.z>b,a.z,b) )'

Joshy

Code: Select all

function max overload(byref a as const v2,byref b as const real) as v2
  return type<v2>( iif(a.x>b,a.x,b),iif(a.y>b,a.y,b) )
end function
function max overload(byref a as const v3,byref b as const real) as v3
  return type<v3>( iif(a.x>b,a.x,b), iif(a.y>b,a.y,b), iif(a.z>b,a.z,b) )
end function
here the complete code

Code: Select all

type real as single ' or double
type v2
  as real x,y
end type
type v3 extends v2
  as real z
end type

function dot overload(byref v as const v2) as real
  return v.x*v.x + v.y*v.y
end function
function dot(byref a as const v2,byref b as const v2) as real
  return a.x*b.x + a.y*b.y
end function
function dot(byref v as const v3) as real
  return v.x*v.x + v.y*v.y  + v.z*v.z
end function
function dot(byref a as const v3,byref b as const v3) as real
  return a.x*b.x + a.y*b.y  + a.z*b.z
end function
function ndot(byref a as const v2,byref b as const v2) as real
  return a.x*b.x - a.y*b.y
end function

function length overload(byref v as const v2) as real
  return sqr(dot(v))
end function
function length(byref v as const v3) as real
  return sqr(dot(v))
end function

function max overload(byref a as const real,byref b as const real) as real
  return iif(a>b,a,b)
end function

function max overload(byref a as const v2,byref b as const real) as v2
  return type<v2>( iif(a.x>b,a.x,b),iif(a.y>b,a.y,b) )
end function

function max overload(byref a as const v3,byref b as const real) as v3
  return type<v3>( iif(a.x>b,a.x,b), iif(a.y>b,a.y,b), iif(a.z>b,a.z,b) )
end function
Last edited by D.J.Peters on Aug 17, 2022 16:21, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: error 67 ?

Post by D.J.Peters »

OK if I change the V3 class (without extends) it works but why ?

Joshy

Code: Select all

type real as single ' or double
type v2
  as real x,y
end type
type v3 'extends v2
  as real x,y
  as real z
end type
fxm
Moderator
Posts: 12106
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: error 67 ?

Post by fxm »

- You can simply help the parser with this syntax (this kind of syntax only works with single inheritance):

Code: Select all

function max overload(byref a as const v3,byref b as const real) as v3
  return type<v3>( type<v2>( iif(a.x>b,a.x,b), iif(a.y>b,a.y,b) ), iif(a.z>b,a.z,b) )
end function

- You can also help the parser by defining constructors (at least for v3 type):

Code: Select all

type real as single ' or double
type v2
  as real x,y
  declare constructor()
  declare constructor(byval x0 as real, byval y0 as real)
end type
constructor v2()
end constructor
constructor v2(byval x0 as real, byval y0 as real)
  x = x0 : y = y0
end constructor
type v3 extends v2
  as real z
  declare constructor()
  declare constructor(byval x0 as real, byval y0 as real, byval z0 as real)
end type
constructor v3()
end constructor
constructor v3(byval x0 as real, byval y0 as real, byval z0 as real)
  x = x0 : y = y0 : z = z0
end constructor

function dot overload(byref v as const v2) as real
  return v.x*v.x + v.y*v.y
end function
function dot(byref a as const v2,byref b as const v2) as real
  return a.x*b.x + a.y*b.y
end function
function dot(byref v as const v3) as real
  return v.x*v.x + v.y*v.y  + v.z*v.z
end function
function dot(byref a as const v3,byref b as const v3) as real
  return a.x*b.x + a.y*b.y  + a.z*b.z
end function
function ndot(byref a as const v2,byref b as const v2) as real
  return a.x*b.x - a.y*b.y
end function

function length overload(byref v as const v2) as real
  return sqr(dot(v))
end function
function length(byref v as const v3) as real
  return sqr(dot(v))
end function

function max overload(byref a as const real,byref b as const real) as real
  return iif(a>b,a,b)
end function

function max overload(byref a as const v2,byref b as const real) as v2
  return type<v2>( iif(a.x>b,a.x,b),iif(a.y>b,a.y,b) )
end function

function max overload(byref a as const v3,byref b as const real) as v3
  return type<v3>( iif(a.x>b,a.x,b), iif(a.y>b,a.y,b), iif(a.z>b,a.z,b) )
end function
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: error 67 ?

Post by D.J.Peters »

@fxm I understand thank you.

Joshy
Post Reply