Is there any way to use anonymous classes in C++ as return types?
I googled that this may work:
struct Test {} * fun()
{
}
But this piece of code doesn't compile, the error message is:
new types may not be defined in a return type
Actually the code doesn't make any sense, I just want to figure out whether an anonymous class can be used as return type in C++.
Here is my code:
#include <typeinfo>
#include <iterator>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
int mx = [] () -> struct { int x, y ; } { return { 99, 101 } ; } ().x ;
return 0;
}
I compile this code with g++ xx.cpp -std=c++0x, the compiler compains:
expected primary-expression before '[' token.