SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.41k stars 477 forks source link

statement does not have a default constructor #1024

Closed frameworker2019 closed 1 year ago

frameworker2019 commented 1 year ago

I'm just trying to hold a statement as a private class member, but struggling to initialize the statement due to missing default constructor.

class A
{
 private:

   statement st;

public:

  A();
...
}

A::A() {

}

Compiler: Constructor for 'A' must explicitly initialize the member 'st' which does not have a default constructor

I've tried:

A::A() : st(session)

A::A() : st(session())

A::A() : st(pool) // pool is indeed known as a reference but doesn't help here

... and a few other crude possibilities, but I can't get them to work in this manner.

vadz commented 1 year ago

Yes, this class doesn't have a default ctor, it needs a session to be created. The simple answer is not to store it as a class member, this rarely makes sense. If you're sure you need to store it, use a (smart) pointer.