# Using TF1 in compiled code with my own function -- what am I doing wrong?

**URL:** <https://root-forum.cern.ch/t/using-tf1-in-compiled-code-with-my-own-function-what-am-i-doing-wrong/55518>\
**Category:** ROOT\
**Tags:** root\
**Created:** [July 2, 2023, 8:21pm UTC](https://root-forum.cern.ch/t/using-tf1-in-compiled-code-with-my-own-function-what-am-i-doing-wrong/55518 "2023-07-02T20:21:33Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Ako\_b](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@Ako\_b](https://root-forum.cern.ch/u/Ako_b)\
**Post date:** [July 3, 2023, 9:29am UTC](https://root-forum.cern.ch/t/using-tf1-in-compiled-code-with-my-own-function-what-am-i-doing-wrong/55518/3 "2023-07-03T09:29:48Z")

</div>

Helllo @sfpate !  
I guess you should use a different `TF1` constructor, [for example](https://root.cern/doc/master/classTF1.html#F4)

```auto
double chi2_p2bm(double *x, double *par)
{
    return pow(x[0]);
}
...
TF1 *fp2bm = new TF1("fp2bm", chi2_p2bm, 0.1, 0.3, 0);

```

Here the last argument `0` to the constructor is number of parameters of function, which is actually zero.

Edit: I just realized that the post above gives a more detailed explanation, so mine is just a duplicate. I apologize for my haste and inattention.

Also, it might be useful to take a look at this post about the use of `new` statement in modern C++:  
[https://root-forum.cern.ch/t/how-to-properly-delete-ttree-and-tgraph-and-renew-them/55351/2?u=ako\_b](https://root-forum.cern.ch/t/how-to-properly-delete-ttree-and-tgraph-and-renew-them/55351/2)

---

_[View the full topic](https://root-forum.cern.ch/t/using-tf1-in-compiled-code-with-my-own-function-what-am-i-doing-wrong/55518)._
