Advertisement
Guest User

Untitled

a guest
Jun 5th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <boost/utility/string_view.hpp>
  4.  
  5. class SomeClass {
  6.  public:
  7.   boost::string_view strView;
  8.   std::string str;
  9. };
  10.  
  11. void SomeFunction(SomeClass& someCopy) {
  12.   SomeClass original;
  13.  
  14.   original.str = "Original string";
  15.   original.strView = original.str;
  16.  
  17.   std::cout << "Original string = " << original.str << std::endl;
  18.   std::cout << "Original string view = " << original.strView << std::endl;
  19.  
  20.   someCopy = original;
  21. }
  22. int main() {
  23.   SomeClass someClass;
  24.  
  25.   SomeFunction(someClass);
  26.  
  27.   std::cout << "Copied string = " << someClass.str << std::endl;
  28.  
  29.  
  30.   // The next string won't work correctly.
  31.   std::cout << "Copied string view = " << someClass.strView << std::endl;
  32.  
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement