Comp Sci Help with C++ Strings: Create a Class Function to Return a String

  • Thread starter Thread starter SEGA
  • Start date Start date
  • Tags Tags
    C++ Strings
AI Thread Summary
To create a class function in C++ that returns a string, the function should simply return the concatenated values of the desired string variables, as demonstrated in the example provided. The discussion highlights the importance of ensuring that all variables are declared correctly to avoid compiler errors. It also notes that C++ supports various string types, prompting the need for clarification on which specific type the user intends to utilize. Understanding the specific string type is crucial for resolving any issues related to the function's implementation. Overall, clear variable declaration and type specification are essential for successfully returning a string from a class function.
SEGA
Messages
2
Reaction score
0
I want to know, how to make a CLASS FUNCTION to return a STRING.
For example, taken that all variables are declared correctly.

string personType::get() const
{
return firstName + " " + lastName;
}
 
Physics news on Phys.org
To return a string, you just return a string. What is your real problem?
 
The compiler write error-type
 
There are many different types of "strings" possible in C++. Which one do you want to use?
 

Similar threads

Replies
2
Views
2K
Replies
12
Views
2K
Replies
10
Views
2K
Replies
14
Views
5K
Replies
2
Views
2K
Replies
7
Views
2K
Replies
1
Views
1K
Replies
2
Views
2K
Back
Top