Compiler Error C3492
'var': you cannot capture a member of an anonymous union
You cannot capture a member of an unnamed union.
To correct this error
- Give the union a name and pass the complete union structure to the capture list of the lambda expression.
Examples
The following example generates C3492 because it captures a member of an anonymous union:
// C3492a.cpp
int main()
{
union
{
char ch;
int x;
};
ch = 'y';
[&x](char ch) { x = ch; }(ch); // C3492
}
The following example resolves C3492 by giving the union a name and by passing the complete union structure to the capture list of the lambda expression:
// C3492b.cpp
int main()
{
union
{
char ch;
int x;
} u;
u.ch = 'y';
[&u](char ch) { u.x = ch; }(u.ch);
}