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

  • Context: Comp Sci 
  • Thread starter Thread starter SEGA
  • Start date Start date
  • Tags Tags
    C++ Strings
Click For Summary

Discussion Overview

The discussion centers around creating a class function in C++ that returns a string, specifically focusing on the implementation details and potential issues encountered during compilation.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • One participant provides a code snippet for a class function that returns a concatenated string of first and last names.
  • Another participant questions the clarity of the original poster's problem, suggesting that returning a string is straightforward.
  • A participant notes that there is a compiler error but does not specify the nature of the error.
  • Another participant points out the existence of various types of strings in C++, asking which specific type the original poster intends to use.

Areas of Agreement / Disagreement

Participants have differing views on the clarity of the original poster's question and the specific issues they are facing, indicating that the discussion remains unresolved.

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 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 24 ·
Replies
24
Views
2K