locked
how to use int^?

    Question

  • How to use int^ in code?

    i see class^ is running well.

    but how can I do for as function below:

    swap(int^ i,int^ j)

    Wednesday, November 16, 2011 10:10 AM

Answers

  • and when I use this in c++ metro dll,it's shown as swap(int* i,int* j) in c# project.

    how can I use it by c#?


    C# does not allow ref arguments (C# ref) in public WinRT methods. C# does allow out arguments though. The C++ equivalent seems to be %. So you could try something like:

    void Swap(int% x, int% y)
    {
    }


    http://blog.voidnish.com
    • Marked as answer by shevaxp Wednesday, November 23, 2011 7:25 AM
    Thursday, November 17, 2011 2:57 PM
  • Ok, I did a quick test. If you have int% as an argument in a C++ WinRT component, a consuming C# client sees it as a ref int. Which is strange because the C# compiler will not allow ref arguments (it insists on those args being out params). Maybe these are glitches in the dev preview that will be sorted out by beta.
    http://blog.voidnish.com
    • Marked as answer by shevaxp Wednesday, November 23, 2011 7:25 AM
    Thursday, November 17, 2011 2:59 PM

All replies

  • How to use int^ in code?

    i see class^ is running well.

    but how can I do for as function below:

    swap(int^ i,int^ j)


    Use int&

    void Swap(int& i, int& j) { }


    http://blog.voidnish.com
    Wednesday, November 16, 2011 1:05 PM
  • How to use int^ in code?

    i see class^ is running well.

    but how can I do for as function below:

    swap(int^ i,int^ j)


    Use int&

    void Swap(int& i, int& j) { }


    http://blog.voidnish.com


    you means that numeric type can not use ^?

     

    Thursday, November 17, 2011 2:36 AM
  • How to use int^ in code?

    i see class^ is running well.

    but how can I do for as function below:

    swap(int^ i,int^ j)


    Use int&

    void Swap(int& i, int& j) { }


    http://blog.voidnish.com


    and when I use this in c++ metro dll,it's shown as swap(int* i,int* j) in c# project.

    how can I use it by c#?

    Thursday, November 17, 2011 3:24 AM

  • you means that numeric type can not use ^? 


    ^ is used with ref-counted objects (COM/RT objects). int is a value type that will live on the stack. So you cannot use ^ with an int. You will need to box an int to use a ^ with it.

    See my article : http://www.codeproject.com/KB/cpp/WinRTVisualCppIntro.aspx and scroll down to the section on boxing for details on how to do that with the dev preview.


    http://blog.voidnish.com
    Thursday, November 17, 2011 2:40 PM
  • and when I use this in c++ metro dll,it's shown as swap(int* i,int* j) in c# project.

    how can I use it by c#?


    C# does not allow ref arguments (C# ref) in public WinRT methods. C# does allow out arguments though. The C++ equivalent seems to be %. So you could try something like:

    void Swap(int% x, int% y)
    {
    }


    http://blog.voidnish.com
    • Marked as answer by shevaxp Wednesday, November 23, 2011 7:25 AM
    Thursday, November 17, 2011 2:57 PM
  • Ok, I did a quick test. If you have int% as an argument in a C++ WinRT component, a consuming C# client sees it as a ref int. Which is strange because the C# compiler will not allow ref arguments (it insists on those args being out params). Maybe these are glitches in the dev preview that will be sorted out by beta.
    http://blog.voidnish.com
    • Marked as answer by shevaxp Wednesday, November 23, 2011 7:25 AM
    Thursday, November 17, 2011 2:59 PM
  • thank you.

    It works well.

    Wednesday, November 23, 2011 7:26 AM