MC++ FAQ
Sunday 04 | 10 | 2005
Order of Property and Field declarations
One common error in MC++ is having a problematic order of property and field declarations in __gc classes. The problem usually manifests when you declare a property with name X and you later declare a field in the same class whose type is also called X. Here's an example:
#using <mscorlib.dll>
using namespace System;


__gc class A {};

__gc class B
{
public:
   __property A* get_A() {
      return a_;
   }
private:
   A* a_;
};

If you compile this, you'll get the following error:

t.cpp(14) : error C2327: 'B::A' : is not a type name, static, or enumerator

The reason for this problem is that the declaration of the the B::A property introduces that name, which later confuses the compiler in the field declaration. The way to fix it is by changing the order and declaring the field first:

#using <mscorlib.dll>
using namespace System;


__gc class A {};

__gc class B
{
private:
   A* a_;
public:
   __property A* get_A() {
      return a_;
   }
};
Posted by tomasr at April 10, 2005 11:16 AM
Comments
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?

Copyright(C) 2002, Tomas Restrepo, All rights reserved. Powered by Movable Type 2.63