LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2009, 04:38 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
Mono and C++


Hi,
i have learned only standard C++ with gcc and i would like to get involved in C++ Windows development. I have understood, that Mono doesn't support C++/CLI - the "new" version, but supports managed C++.
Is this possible to run this sample program, found in the internet? I would like to learn how, step-by-step. Is there a link? I have not found something... I am a newbie and any help will be appreciated.

Thanks

Code:
#using <mscorlib.dll>

using namespace System;

// A simple class

__gc class CHelloWorld
{
  System::String *_msg;
public:
  CHelloWorld(System::String *Msg)
  {
    _msg = Msg;
  }

  void Print()
  {
    Console::WriteLine(_msg);
  }
};

// Yet another class w/ but a static constructor

__gc class CHelloWorldStatic
{
  static System::String *_static_msg = 
    S"Static message called because static constructor invoked!";
  static Int32 _instance_cnt = 0;

public:

  // constructor

  CHelloWorldStatic()
  {
    _instance_cnt++;
    Console::WriteLine(System::String::Concat("So far ", 
             _instance_cnt.ToString(), " instance(s)"));
  }

  // static constructor making use of the static member

  static CHelloWorldStatic()
  {
    Console::WriteLine(_static_msg);
  }

};

int main()
{
  // create an instance of the class

  CHelloWorld *c1 = __gc new CHelloWorld(S"Hello world from the class");

  c1->Print();

  // take an instance of the class that has static constructor

  // now we will notice that first, the static constructor

  // will be called, then the ordinary constructor

  CHelloWorldStatic *c2 = __gc new CHelloWorldStatic();

  return 0;
}
 
Old 02-19-2009, 11:14 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Programming a .Net application in C++ is kind of like programming a Java application in Ada. You can *do* it (http://code.google.com/p/jgnat/) ... but why bother?

Despite Microsoft's claim of being "language agnostic" (which, btw, isn't "untrue"...) ... VB.Net and C# are really the only two languages I'd recommend (and of course ASP.Net for server-side web pages).

Conversely, coding "standard C++" (managed or unmanaged code) has become increasingly unpleasant with newer versions of VS2008 - I'd prefer GCC for C/C++ any day :-)

All my own opinions (for whatever it's worth): but I'd definitely recommend *not* trying to program .Net on C++.

IMHO .. PSM

PS:
Your code snippet is .Net-to-the-max: I have no idea how I'd go about trying to compile, link and run it with Gcc (for example).

PPS:
You might also be interested in looking at Microsoft's "Visual Studio Express" offerings here (they're perfectly functional, and great tools):

http://www.microsoft.com/express/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mono ???!! basslk Linux - General 1 04-10-2008 02:59 PM
paint-mono (Paint.net for Mono) Installer? caa1980 Linux - Software 0 10-03-2007 10:52 AM
Help Mono Installed But Mono Develop Won't Load TheGreatGonzo Slackware 8 05-18-2006 06:42 AM
Mono Wolfmann Programming 6 01-03-2006 10:43 AM
mono gtzpower Linux - Software 0 08-17-2004 08:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration