-1

In order to avoid unnecessary variables, is there a way to make

int var = sharedPtrStringVar.length();

and other funtions of String work with smart pointers?

Until now I`ve been copying the string from the pointer into a temp var but isn't there a better way (without using vectors)?

thnak you Yksisarvinen that was exaclty what i wanted to kinow

Nerrock
  • 3
  • 2

1 Answers1

5

Similarly to raw pointer, you use -> operator to access object members, so your code would be

int var = sharedPtrStringVar->length();

Same applies to dereference operator *:

int var = (*sharedPtrStringVar).length();
std::cout << *sharedPtrStringVar; //print the content
Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52