Re: [Vala] Passing Ownership Help

On Sun, Jul 10, 2011 at 02:36:23AM +0900, Peter Cartwright wrote:
Hi guys,

I am trying to understand how a function can take ownership of an object
passed into it. According to documentation it should be like below:

MyList.add (owned Person p) {
  _first = (owned) p;

Person p = new Person ("Bobby");
List.add (p);
stdout.printf ("%u\n", p.ref_count);

But when I do it like this and check the reference count of p, it is equal
to 2... shouldn't it be 1? I want the list to be the new owner of P.

You're still owning p in that scope. You want List.add ((owned) p);

-- - The Universal Operating System

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]