Function

hi,
can a function return a class or class handle ?
if does can any one explain me with example.

thanks

In reply to lalithjithan:
Yes you can return an object.

In reply to lalithjithan:

The function can return the “class handler” (can’t return a class, I don’t know what you mean to return a “class” in function):


function my_class get_object();
  my_class handler = new;
  // Do something
  return handler;
endfunction

// To use
my_class handler = get_object();

However, you can also pass the object handler to function and modify inside the function:


function void get_object(my_class handler_copy);
  // Do something
endfunction

// To use
my_class handler_original = new;
get_object(handler_original);

Why it works? When you pass object handler to a function by value, the object handler will be copied (stored in stack). We have 2 handlers (handler_original and handler_copy) which point to same memory location where the object is created. When you modify the “handler_copy” in function, the “handler_original” is also changed.