Managed and Unmanaged Compilation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • romcab
    New Member
    • Sep 2007
    • 108

    Managed and Unmanaged Compilation

    Hi guys,
    I created a simple program which combines a managed and unmanaged c++ syntax. I have encountered a problem in compiling this program. The compiler told me to add /clr:oldSyntax but when I added it, the compiler cannot interpret the managed syntax. Hope you can help me.

    #include "stdafx.h"

    using namespace System;

    __nogc class Container
    {
    int m_value;

    public:
    Container() : m_value(0) {}
    void setValue(int* a_value) { m_value = *a_value; }
    const int& getValue() { return m_value; }

    };

    int main(array<Syst em::String ^> ^args)
    {
    Console::WriteL ine(L"Hello World");
    return 0;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Originally posted by romcab
    I created a simple program which combines a managed and unmanaged c++ syntax. I have encountered a problem in compiling this program. The compiler told me to add /clr:oldSyntax but when I added it, the compiler cannot interpret the managed syntax.
    Hi, I suspect the compiler was guess at your mistake and got it wrong (no surprise there), /clr:oldSyntax is only for use with legacy projects built with Managed C++ syntax before the newer C++/CLR syntax came in.

    I suggest your remove /clr:oldSyntax compile and post the errors you get from that compilation.

    Comment

    • romcab
      New Member
      • Sep 2007
      • 108

      #3
      Originally posted by Banfa
      Hi, I suspect the compiler was guess at your mistake and got it wrong (no surprise there), /clr:oldSyntax is only for use with legacy projects built with Managed C++ syntax before the newer C++/CLR syntax came in.

      I suggest your remove /clr:oldSyntax compile and post the errors you get from that compilation.

      Hi,

      Thanks. I post here my solution. Kindly comment if this correct.

      // Managed.cpp : main project file.

      #include "stdafx.h"

      using namespace System;


      class MyBase
      {
      private:
      int m_value;

      public:
      MyBase() : m_value(0) { Console::WriteL ine(L"MyBase constructed is called"); }
      void setValue(int a_value) { m_value = a_value; }
      const int getValue() { return m_value; }

      };


      public ref class MyClass
      {
      public:
      MyBase *mb;

      public:
      MyClass()
      {
      this->mb = new MyBase();
      Console::WriteL ine(L"MyClass constructed is called");
      }
      };

      int main(array<Syst em::String ^> ^args)
      {
      MyClass ^my = gcnew MyClass();
      my->mb->setValue(5);
      Console::WriteL ine(my->mb->getValue());
      Console::ReadLi ne();
      return 0;
      }

      Comment

      Working...