Refactor with "Convert Between Pointer and Instance" to change object pointers to object references, and vice versa. The refactoring converts a declaration, swaps "." and "->" in references, and adjusts "*" and "&" as necessary.
Access
Access "Convert Between Pointer and Instance" via the context menu of the text editor (Right-click or Shift+F10), or via the Quick Actions and Refactoring menu (Shift+Alt+Q). The command is available only when the text caret is on the declaration of a local variable.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpimenu.ashx?la=en&hash=3D98F482D7DB7AA006A1343691593074C37E92AE)
Convert Pointer to Instance
When converting a pointer to an instance, select the references to convert in the dialog that opens. References to "delete", if any, will be removed.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpidialogp2i.ashx?la=en&hash=8AFB06A7CD5072599D4286AF2F9F3282E1A4EFAD)
Convert Instance to Pointer
When converting an instance to a pointer, select the pointer type in the dialog that opens. If converting to a raw pointer, you must manage the lifecycle of the pointer, e.g. add a "delete" when the variable is no longer needed.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpidialogi2p.ashx?la=en&hash=01C99313FE9E4CD92D4AF6D10B4D2114D11DAE27)
If you convert to a smart pointer, the converted declaration will use std::make_unique or std::make_shared.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpimakeshared.ashx?la=en&hash=CE5B199AC48476C04ED8DEB7152B4F509D372740)
By default, the converted variable will be declared using "auto". Uncheck use-auto in the dialog to convert using an explicit type.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpimakesharedexplicittype.ashx?la=en&hash=2CC8A2D7E2E1CBD63E89C91EF5D5ECFE7CE21CBE)
To convert an instance to a pointer using a template, select "custom" and enter a name of a function template. Optionally, enter an explicit type.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpicustom.ashx?la=en&hash=B0D1115869945193014E7F203C8EA481BF1DD164)
If you omit a type, the converted variable will be declared using "auto".
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpicustomconverted.ashx?la=en&hash=9504B304D6B7AE8E51DD2A84578E1486297D733D)
Unsupported Scenario
A message appears if "Convert Between Pointer and Instance" cannot refactor the selected variable.
![](/~/media/wholetomato/kb/documentation/convert-between-pointer-and-instance/cpierror.ashx?la=en&hash=05D6716A4DADD8AF039077BBE1B6CB6A9F93BDC4)