I am trying to write a wrapper class which wraps around another class containing c based header files and functions.

Here is the original problem to which I am trying to find a workaround.

This is the class which calls the c functions and should be encapsulated:

#include "c_header.h"

class A
{
public:
          void foo () { 
          function();  //calling a function of the c based library
        }; 
};

Here is how I created the wrapper class (.lib) to encapsulate the class A :

#include "A.h"
class wrapper  
{
public:
    void  test()
        {
          wa-> foo()
        };
private:
    A* wa;
};

And here is the test project in which I was hoping to call the wrapper class library without the need to know about the class A (c_header.h and its functions).

#include "wrapper.h"

void main(){
    wrapper *w = new wrapper;
    w->test();
}

The test main does not compile and issues linker problems complaining about the functions inside class A (here function()).

The codes are in windows7 and visual studio2015.

Could anyone help me with really encapsulating/wrapping another class without the need for the header files?

Thanks in advance.

1 Answers

2
Paul Evans On

You need to tell the compiler/linker it's a C header:

extern "C" {
#include "c_header.h"
}