Examples of ISO C++ code that is not valid C++/CLI

后端 未结 2 1870
轮回少年
轮回少年 2021-01-18 21:30

I\'ve seen contradictory answers on the internet with regard to whether C++/CLI is a superset of C++ or not.

The accepted answer on this question claims that \"tech

2条回答
  •  后悔当初
    2021-01-18 22:25

    Valid C++, invalid C++/CLI:

    int main()
    {
        int gcnew = 42;
    }
    

    gcnew, generic, and nullptr are all reserved words in C++/CLI; nullptr isn't really an issue in C++0x, of course. Herb Sutter blogged about C++/CLI keywords: Under the hood in 2003.

    For what it's worth, when I was working on a large mixed codebase (both C++ and C++/CLI), I never ran into syntax issues or trivial issues like this. The giant issue with C++/CLI (in my opinion, of course) is that native code and managed code have completely different resource management paradigms, and it's really easy when writing mixed code to forget which paradigm you need for certain things. I fixed a lot of errors that were due either to an assumption that managed resources were destroyed deterministically or that native resources would be cleaned up by the garbage collector.

提交回复
热议问题