cpp-sqlitelib icon indicating copy to clipboard operation
cpp-sqlitelib copied to clipboard

Parent class gets deleted upon initialization of sqlitelib's class

Open bastien8060 opened this issue 4 years ago • 1 comments

Hello! I really like this project, however, I have come to an error, which I couldn't fix. It seems that when you initialize a database with sqlitelib in a class, then the =delete operator gets called on the parent class. Eg:

Here I have a class: PokeDex. The classes initializes itself with a database. (I also tried to move the definition to the constructor). It seems my PokeDex object gets deleted.

class PokeDex {       // Sample class
  public:
    Pokemon GetPokemon(string name) const;
    PokeDex();
    sqlitelib::Sqlite db = sqlitelib::Sqlite("./test.db");
};
includes/sqlitelib/sqlitelib.h:279:3: note:   candidate expects 1 argument, 0 provided
dexserver.cpp: In function ‘int main()’:
dexserver.cpp:13:42: error: use of deleted function ‘PokeDex::PokeDex(const PokeDex&)’
   13 |     CROW_ROUTE(dex, "/pokemon/<string>")([pokedex](std::string name){
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   14 |         Pokemon result = pokedex.GetPokemon(name);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 |         std::string body = result.description;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   16 |         return body;
      |         ~~~~~~~~~~~~
   17 |     });

bastien8060 avatar Nov 14 '21 11:11 bastien8060

Without sqlitelib, the code works perfectly. Finally, I experimentally removed all occurrence with =delete in sqlitelib.h to no avail.

bastien8060 avatar Nov 14 '21 11:11 bastien8060