The __identifier keyword

While the contingency is not all that probable, it cannot be totally ruled out that a C# or VB.NET component developer might inadvertently use a C++ keyword as a class name or a public field name. Anyway, the C++ team decided that they had to allow for this probability and gave us the __identifier keyword which allows us to use C++ keywords as identifiers in C++ source code.

See the following C# class library :-

/*
    csc /t:library Class1.cs
*/

public class gcnew
{
    public gcnew()
    {
        generic = 25;
    }

    public int generic;
}

To use it from C++, you can use the __identifier keyword as shown below :-

/*
    cl/clr /FUClass1.dll Prog1.cpp
*/

int main()
{
    __identifier(gcnew)^ g = gcnew __identifier(gcnew)();
    int x = g->__identifier(generic);
    return 0;
}
Advertisements

2 thoughts on “The __identifier keyword

  1. Just when I thought the team has got rid of the underscores ;-p I’m back in town after a eventful fortnight 🙂

  2. I read your blogs and i like them because you mix your social
    life events with your c++ events. I want to make money with
    making all kinds of user programs and sell them on download.com
    or something. I have no idea what a MicroSoft c++ programmers
    earns in a monthly salary but could you tell me yours so I will
    have some idea ?
    Greetings
    Enrico

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s