Note that there are some explanatory texts on larger screens.

plurals
  1. POMy string isn't copying from private variables
    primarykey
    data
    text
    <p>Everything in my coding works except the get and set name functions. When I call getName, it prints blank. I've tried a few different solutions, but the only thing that has worked is actually saving the fullName string inside of main, and calling it from there. It's almost as if it's not letting me call the variables because they are private.</p> <p>Here is my .cpp file.</p> <pre><code>#ifndef STUDENT_H #define STUDENT_H #include &lt;iostream&gt; #include &lt;string&gt; #include "Student.h" using namespace std; int main() { //for student name string firstName; string lastName; string fullName; //student name cout &lt;&lt; "Please enter your students first name" &lt;&lt; endl; cin &gt;&gt; firstName; cout &lt;&lt; "firstName = " &lt;&lt; firstName &lt;&lt; endl; cout &lt;&lt; "Please enter your students last name" &lt;&lt; endl; cin &gt;&gt; lastName; cout &lt;&lt; "lastName = " &lt;&lt; lastName &lt;&lt; endl; aStudent.setName(firstName, lastName); fullName = aStudent.getName(); cout &lt;&lt; "Your students name is : "; cout &lt;&lt; fullName &lt;&lt; endl; } #endif </code></pre> <p>Here are my functions, and class, .h file.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;conio.h&gt; using namespace std; class Student { private: string fName; string lName; public: string getName(); void setName(string firstName, string lastName); }; string Student::getName() { return fName + " " + lName; } void Student::setName(std::string firstName, std::string lastName) { firstName = fName; lastName = lName; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload