oatpp / example-mongodb

Example project how to work with MongoDB

Home Page:https://oatpp.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Order of initialization might be wrong

kiskit opened this issue · comments

Hello,

First and foremost, I'm not 100% certain of what I'm going to say, but...
In AppComponent.hpp, you initialize the m_cmdArgs member in the contructor (line 28).
A bit later in the code (line 70), you use the OATPP_CREATE_COMPONENT macro to create a component, and in the associated lambda, you try to use that m_cmdArgs member.
I've been struggling with my own code and I suspect it's because the OATPP_CREATE_COMPONENT macro (and most of all the lambda) will be executed before the AppComponent constructor.
So I think that, in you code, you try to make use of a member that has not been initialized.
On a more generic note, I've been trying to pass a configuration structure to that constructor. If I'm right, all component members that depend on it must be initialized differently, like in the body of the constructor. Maybe it's worth mentioning somewhere.

And now I've found out that you had thought of it, hence the previous declaration of m_cmdArgs to ensure the order of construction.
My bad.