Topic: Name confusion


Author: Jami Bradley <Bradley@ieclon.com>
Date: Fri, 22 Nov 2002 12:27:09 CST
Raw View
I am in the process of porting some code and came across a compilation
error.  Here is an example of the error:

class B1
{
   public :
      typedef struct X
      {
         int Member;
      } X;
};

class B2
{
// int    B1;  // This works
   B1::X  B1;  // This does not
};

// Results from gcc:
// GNU C++ version 2.95.4 20011002 (Debian prerelease) (i386-linux)
// compiled by GNU C version 2.95.4 20011002 (Debian prerelease).
// Test.cpp:13: declaration of `struct B1::X B2::B1'
// Test.cpp:8: changes meaning of `B1' from `class B1'

I can understand why it is getting confused - declaring a member
variable using the same name as a class.  I would like to change the
name, but we have customers using the code, so I don't want to change
it unless necessary.  VC++ doesn't have any trouble with this code.

So, is this legal ANSI C++ or not?

Thanks,

Jami

IEC Intelligent Technologies
Creator of Peak Components, a high-performance low-cost network
management solution for EIA 709.1
See our website at http://www.ieclon.com/

Jami Bradley
Director, Software Engineering             Voice: 303.277.1503
bradley@ieclon.com                           Fax: 303.277.1522

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]