The local variable of string is getting corrupted immediately after passing the lambda function as an argument to a constructor.
I have tried my best to mimic the code in my project. The issue in my project is that second cout of string is printing an empty string.
Could someone tell me what is wrong here.
using CB = std::function<void(const uint8_t *data, size_t size)>;
class CLASS_A
{
public:
CLASS_A(CB cb, std::string NAME = DEFAULT_NAME);
};
class CLASS_B
{
public:
CLASS_B();
void fun1(void);
};
CLASS_A::CLASS_A(CB cb, std::string NAME)
{
}
CLASS_B::CLASS_B()
{
}
void CLASS_B::fun1(void)
{
std::string s;
s="asdfg";
CLASS_A obja([this](const uint8_t *data, size_t size)
{
});
std::cout << "s = " << s << std::endl;
}
int main(void)
{
CLASS_B objb;
objb.fun1();
return (0);
}
Output :
s=asdfg
s=
Aucun commentaire:
Enregistrer un commentaire