Long story short, I am trying to build a wrapper to access C++ source code from a C main function (I have to do the conversion because of Embedded systems); however, I am having trouble calling the methods from the class to an external function without creating an instance of that class.
I want to pass this *side
pointer from my C code, calculate the cube of it, and get returned the cubed value. I have tested my wrapper with simple pointer functions and variables and it works perfectly fine, however I am having trouble with class methods. Here is my source code to that, with the mistake I am making on the last line...:
class Cube
{
public:
static int getVolume(int *side)
{
return *side * *side * *side; //returns volume of cube
}
};
void Cube_C(int *side)
{
return Cube.getVolume(*side);
}
int*
instead of just anint
?int cubeSide = 5; printf("Cube of 5 is: %d\n\n", GetVolume_C(&cubeSide));
In the meantime I useextern"C"
on a header file to link the C with C++.int
? If you check my example in the answer I gave, there are no pointers.