Click here to Skip to main content
15,894,405 members
Articles / Programming Languages / C++14

How to Return a String Class from a C++ Function/Method

Rate me:
Please Sign up or sign in to vote.
1.94/5 (5 votes)
27 Dec 2020CPOL4 min read 15.7K   7  
Use STL and C++14 to return a dynamically created string from a function/method, that is automatically garbage collected.
What I want to show here is not a new or surprising trick, but simply the consistent use of the possibilities available since C++14 to use a "clean" memory management for the return of dynamically allocated memory. The main use case are certainly strings. My string class serves here only as an easy to understand example to explain the approach.

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Celonis SA
Germany Germany
I am currently the CEO of Symbioworld GmbH and as such responsible for personnel management, information security, data protection and certifications. Furthermore, as a senior programmer, I am responsible for the automatic layout engine, the simulation (Activity Based Costing), the automatic creation of Word/RTF reports and the data transformation in complex migration projects.

The main focus of my work as a programmer is the development of Microsoft Azure Services using C# and Visual Studio.

Privately, I am interested in C++ and Linux in addition to C#. I like the approach of open source software and like to support OSS with own contributions.

Comments and Discussions