assignPtr()

The function allows to assign a shared_ptr to a different shared_ptr..

Synopsis

int assignPtr(shared_ptr &target, shared_ptr source);

Parameter

  1. Parameter Description
    target Target shared_ptr to which the source shared_ptr is assigned. The "target" pointer is detached from the original source before assigning the new "source" pointer.
    source shared_ptr that should be assigned.

Return Value

Success returns 0; in case of an invalid argument returns -1

Errors

The function returns an exception in case the shared_ptr objects are not compatible.

Description

The function allows to assign a shared_ptr to another shared_ptr. Before assigning the "source" pointer to the "target" pointer a null pointer is assigned to the "target" and therefore overridden and detached.

The same result can be achieved using following code:

target = nullptr;
target = source;

The function unpacks the target parameter. E.g.:

  dyn_anytype da;
  da[1] = new int(1);  //this creates an anytype which itself holds a shared_ptr which points to an int
  assignPtr(da[1], new int(8));

Assignment

CTRL++

Availability

CTRL,UI