statement does not have a default constructor
frameworker2019 opened this issue · 1 comments
frameworker2019 commented
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
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.