-1

I have a C code function, which I need to call from the class constructor.

Class a{
.....
}
//Included the header file in the class and
//declared the function globally as extern 
extern void ab(void); //function available in the c code 
a::a() //constructor of class a
{
::ab(); //calling the non member function - giving an error
}

It is giving an error : undefined reference to `ab()'

Can anyone help me to solve this issue?

tharunkumar
  • 2,801
  • 1
  • 16
  • 19

2 Answers2

1

Judging simply from the code and error supplied, it look as if you have not DEFINED your function. You have DECLARED it, but the compiler is complaining that it cannot find that function's implementation. To resolve this, provide an implementation for your function e.g.

void ab(void)
{
    int x = 0;
    printf("My int: %d", x);
}
Serge
  • 634
  • 4
  • 9
  • ab() function is calling the another function, which is doing the serial bus initialization with the predefined values. – tharunkumar Mar 24 '16 at 06:49
-2

Send pointer as a parameter to the constructor:

a::a(void (*ptrFun)(void) )
{
     ptrFun();
}
Rafał
  • 19
  • 5