TgBot-cpp. I can’t understand what is wrong with answerInlineQuery() [closed]

I am trying to use answerInlineQuery(), but I have error read access violation. I can’t understand where is problem.

bo.getEvents().onInlineQuery([&bo](TgBot::InlineQuery::Ptr mes) {
    std::cout << "chto-to\n";

         TgBot::InlineQueryResultArticle::Ptr pr,pr2;
         TgBot::InputTextMessageContent::Ptr ptrr,ptrr2;
         ptrr->messageText = "message1";
         ptrr2->messageText = "message2";

         std::vector<TgBot::InlineQueryResult::Ptr> vec;

         pr->title = "chel";
         pr->description = "xz";
         pr->inputMessageContent = ptrr;
         vec.push_back(pr);

         pr2->title = "chel2";
         pr2->description = "xz2";
         pr2->inputMessageContent = ptrr2;
         vec.push_back(pr2);

         if (mes->query == "d20") {
             std::cout << "d20\n";
             mes->offset = "qwer";

             bo.getApi().sendMessage(mes->from->id, mes->offset);
             bo.getApi().answerInlineQuery(mes->id, vec);
            
         }

    });

There is photo of problem

enter image description here

I was looking for all possible necessary objects and I defined them, but it didn’t help.

  • Looks like you’re trying to use uninitialized pointers. Try using your debugger to find out more details, which one exactly.

    – 

  • literally here : TgBot::InputTextMessageContent::Ptr ptrr,ptrr2; ptrr->messageText = "message1"; I would be afraid to look at the rest of code after this. Ptr is just std::shared_ptr<InputTextMessageContent>

    – 




  • Specifically ptrr->messageText = "message1"; ptrr2->messageText = "message2"; is wrong, these pointers aren’t initialized. Check the docs how are you required to do this.

    – 

Leave a Comment