convert to cpp
Fixing pointer issue