parent declare, child define

General FreeBASIC programming questions.
Post Reply
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

parent declare, child define

Post by dafhi »

my primary interest here is to use constants because my understanding is that they are speedy

in the child class, i wish different constants, with the possibility of having Many child objects

i'm looking to offload text to parent in the interest of less typing / rapid prototyping but the definitions use the child constants

here's example

Code: Select all

type tRNG_Parent
    
    as long           state, invMul_
  
    ' use child-defined constants.
    declare operator  cast as ulong
    declare function  f(as long=0)as ulong
    declare function  r(as long=0)as ulong
    declare constructor
    
End Type

'' use child-defined constants
function tRNG_Parent.f(i as long) as ulong
    asm ror dword ptr [i], ro
    state = (i + add_) * mul_
    return state
End function

function tRNG_Parent.r(i as long) as ulong
    i = (i * invmul_ - add_)
    asm rol dword ptr [i], ro
    state = i:  return i
End function

operator tRNG_parent.cast as ulong
    return f(state)
End Operator


type tRNG extends tRNG_Parent
    
    const             ro = 30
    const             mul_ = 3
    const             add_ = 1
    
End Type
Post Reply