473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Managed and Unmanaged Compilation

108 100+
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<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
Feb 20 '08 #1
2 1443
Banfa
9,065 Expert Mod 8TB
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.
Feb 20 '08 #2
romcab
108 100+
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::WriteLine(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::WriteLine(L"MyClass constructed is called");
}
};

int main(array<System::String ^> ^args)
{
MyClass ^my = gcnew MyClass();
my->mb->setValue(5);
Console::WriteLine(my->mb->getValue());
Console::ReadLine();
return 0;
}
Feb 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
3
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the...
3
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the...
6
by: nicolas.hilaire | last post by:
Hi all, i'm not totally clear with some concepts about managed and unmanaged code. I'm asking myself some questions : - i've a MFC app, i want to use the framework dotnet by switching to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.