[RESOLVED] Convert From C# to Managed C++ and C++/CLI
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Convert From C# to Managed C++ and C++/CLI

  1. #1
    Join Date
    Dec 2011
    Posts
    53

    [RESOLVED] Convert From C# to Managed C++ and C++/CLI

    Hi Iam tryin to convert my Digit To Words class from c# to VC++... And the following line I am facing trouble

    String^ strNum;
    String^ strNumDec;
    String^ StrWord;
    strNum = Convert::ToString(Num); // Num is Decimal Parameter
    blah..blah...blah...

    StrWord = ((double.Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((decimal)(double.Parse(strNum))) + ((double.Parse(strNumDec) > 0) ? (" and Paise" + cWord3((decimal)(double.Parse(strNumDec)))) : "");

    Thanks

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    Re: Convert From C# to Managed C++ and C++/CLI

    What is the problem?

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,591

    Re: Convert From C# to Managed C++ and C++/CLI

    If what you posted is the actual code you tried to compile as C++/CLI, you're facing two syntactical issues:

    While C# uses the dot operator for all sorts of class member access, C++/CLI uses that one for instance members of value types only. For instance members of reference types it uses -> instead, and :: for static members of both reference and value types.

    Unlike C#, C++/CLI doesn't feature a keyword synonym for the System::Decimal type. So you'd need to write it with a capital D to directly refer to the actual type. (I assume you have a using namespace System; in effect, since otherwise you couldn't declare String variables without explicitly specifying the namespace either.)

    This would lead to the following changes to your code line:

    Code:
    StrWord = ((double::Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((Decimal)(double::Parse(strNum))) +
      ((double::Parse(strNumDec) > 0) ? (" and Paise" + cWord3((Decimal)(double::Parse(strNumDec)))) : "");
    Also, C-style casts as we have them here should generally be avoided. Here I'd suggest to at least use static_cast instead. Admittedly, that will make the code look even more ugly and make it harder to read. Why not simply parse to a Decimal directly using Decimal::Parse()??

    And please use code tags when posting code.
    Last edited by Eri523; April 28th, 2014 at 01:07 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Dec 2011
    Posts
    53

    Re: Convert From C# to Managed C++ and C++/CLI

    Thanks Eri...Your reply cleared me very well.
    Thanks for all replies.

    Thanks & Regards
    Mahey

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center