This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Anonymous struct


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]