calling a function (passed as a pointer) causing segmentation fault

S

sandwich_eater

I get a segmentation fault in my program when calling a function
"TestFn" that has been passed as a pointer into another function.
The following excerpt should give enough information as to what I am
doing wrong...

typedef void TIdxMultiFunc (int i, std::vector<double> f);

void TestFn(int i, std::vector<double> f)
{
double t; // execution does not get this far
...
f[0] = t*t;
f[1] = t*t*t;
}

void TestSolve(std::vector<double> &a)
{
....
TIdxMultiFunc *ptr = &TestFn;
afn(y, ptr, 2);
}

void afn(std::vector<double> &y, TIdxMultiFunc *f, int n)
{
....
int i;
std::vector<double> bf;
bf.resize(ndata - 1);

for (i = 0; i < n; i++)
{
f(i, bf); // segmentation fault occurs here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top