Anonymous struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can someone with a good understanding of the C++ standard tell me if this program is legal C++

#include <iostream>
int x = 1;
int main(int argc, char** argv)
{
   struct {
       int operator()( int y ) { return x + y; }
   } fun;

   std::cout << fun( 7 ) << std::endl;
   return 0;
}

It compiles and runs with gcc 4.4.1. I have done similar things in other situations many times, so I assumed that it was valid.

But another compiler (not a version of GCC) reports:

error C2627: member function defined in unnamed class

I hope that other compiler is just wrong. But I'd like someone with a better understanding of the standard to comment.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux