# Function Pointer Inside a Jitclass

**URL:** <https://numba.discourse.group/t/function-pointer-inside-a-jitclass/903>\
**Category:** Community Support\
**Created:** [September 9, 2021, 11:16am UTC](https://numba.discourse.group/t/function-pointer-inside-a-jitclass/903 "2021-09-09T11:16:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArthurRocha](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/arthurrocha/32/400_2.png) [@ArthurRocha](https://numba.discourse.group/u/ArthurRocha)\
**Post date:** [September 9, 2021, 11:16am UTC](https://numba.discourse.group/t/function-pointer-inside-a-jitclass/903/1 "2021-09-09T11:16:03Z")

</div>

Dear all,  
I am trying to create a class similar to the one below.

```auto
spec = [("x", nb.float64), ("y", nb.float64)]
@nb.experimental.jitclass(spec = spec)
class MyClass:
    def __init__ (self, x, square):
        self.x = x
        if square:
            f = self.x_squared
        else:
            f = self.x_simple
        self.y = f()     

    def x_simple(self):
        return self.x
    
    def x_squared(self):
        return self.x**2

object = MyClass(x = 2.1, square = True)
print("x = ", object.x)
print("y = ", object.y)

```

But it raises an error when trying to compile the call of the **f** function. Is there a way to use a variable inside a jitclass as a function pointer to the methods of the same jitclass?

Thank you for your help,  
Arthur.

---

<div class="post-metadata">

**Author:** ![luk-f-a](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/luk-f-a/32/56_2.png) [@luk-f-a](https://numba.discourse.group/u/luk-f-a)\
**Post date:** [September 10, 2021, 6:56am UTC](https://numba.discourse.group/t/function-pointer-inside-a-jitclass/903/2 "2021-09-10T06:56:13Z")

</div>

hi @ArthurRocha , I haven’t tried it but it might be possible by explicitly declaring `f` in the spec to be a function. This thread will show you how to declare variable to be of function type: [Typed list of jitted functions in jitclass - #3 by hgrecco](https://numba.discourse.group/t/typed-list-of-jitted-functions-in-jitclass/413/3)

Hope this helps, don’t hesitate to share the result and final code! it might help the next person!

Luk
