I want to define a parameter inside if . for example
if(MyDataPtr && auto* InfoPtr = MyDataPtr ->extractInfo())
And gen compilation error Expected ')'
Is it impossible? or what ca be done? - i don`t like the code bellow - looking for better (elegant) implementation
if(MyDataPtr)
{
auto* InfoPtr = MyDataPtr ->extractInfo();
if (InfoPtr )
//some code
}
Unfortunately you can't define variables in the middle of expressions. But you can define a variable as a single expression and use it as a condition, which will simplify your code a little bit:
Is it more "elegant"? To some perhaps.