locked
How can i write reference parameter in WinRT? RRS feed

  • Question


  • void test(int& id) {

    id =5; }

    How can i  write reference parameter in WinRT? 

    Thursday, November 8, 2012 4:49 AM

Answers

  • You can not have reference parameters (which could be in/out) on the public surface of a C++/CX component but you can have out parameters in WinRT. The following methods can be public methods on a public ref class:

    void func(int* id)
    {
        if (id != nullptr) *id = 5;
    }
    
    void func(IVector<int>^* ids)
    {
        if (ids != nullptr) 
        {
             *ids = ref new Platform::Vector<int>();
             (*ids)->Append(10);
             (*ids)->Append(20);
        }
    }
    
    Hope this helps,
    Marian Luparu
    Visual C++
    Thursday, November 8, 2012 7:00 PM

All replies