0

I'm working on a software library, where one of the headers is written like this:

#include "exprtk.hpp"

class ExprtkWrapper {
    typedef exprtk::symbol_table<double> symbol_table_t;
    typedef exprtk::expression<double>     expression_t;
    typedef exprtk::parser<double>             parser_t;


public:

    API ExprtkWrapper( std::string expression_string );

    API ExprtkWrapper( );

    API ~ExprtkWrapper();

    API double eval(double x1 = 0.0, double x2 = 0.0, double x3 = 0.0, double x4 = 0.0);

    API double eval(std::vector<double> &p);

private:

    expression_t *expression = nullptr;

    symbol_table_t *symbol_table = nullptr;

    parser_t * parser = nullptr;    
};

It needs exprtk library to work. The problem is, that exprtk.hpp is a header-only library and I don't want it to be copied wherever I include my header. Is there any elegant way to rewrite the header to get exprtk.hpp to the corresponding .cpp file?

I've tried simply rewriting my class into the cpp file and leaving just declaration in the header, but then I'm getting the error:

error: invalid use of incomplete type ‘class ExprtkWrapper’
Eenoku
  • 2,369
  • 2
  • 26
  • 45
  • When you are willing to use something out of a header only library, you always have to include the whole file. What you can do to reduce compile time is to use pre compiled headers. – JulianH Sep 13 '18 at 20:23
  • 1
    It looks like `exprtk` provides templates. You should read [this question](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file). – François Andrieux Sep 13 '18 at 20:24
  • If you aren't exposing any templates to you library's users, then you can simply not expose that header. Presumably, any template you need from that library would have been instantiated when you compile your library. You'd need some facade header that hides `exprtk` related details. – François Andrieux Sep 13 '18 at 20:25
  • 4
    Pimpl idiom might help. Looks like you only use the library in the private part of the class - Pimpl is designed precisely to hide that. – Igor Tandetnik Sep 13 '18 at 20:26
  • @FrançoisAndrieux Thank you very much! Would you mind to write a short example of such facade header? – Eenoku Sep 13 '18 at 20:28
  • @Eenoku Take a moment to read about the [pimpl idiom](https://stackoverflow.com/questions/8972588/is-the-pimpl-idiom-really-used-in-practice). It can be used to hide any implementation details used by your class. – François Andrieux Sep 13 '18 at 20:31

0 Answers0