Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting back into c++, void function with pointers, how to make get function
    text
    copied!<p>I have a project I'm working on that's actually a school project that I did successfully a long time ago. I haven't done C++ in a while, and I'm having a bit of a problem jumping back into it, especially with pointers. My question is, if I need a get and set function like this</p> <pre><code> class Student { private: char firstName[64]; char lastName[64]; public: void setName(char *fName, char *lName); void getName(char *fName, char *lName); } void Student::setName(char *fName, char *lName); { firstName = *fName; lastName = *lName; } </code></pre> <p>when try to make my getName function, I seem to be very confused as to how I'm supposed to return the names with the function returning void. I know that it doesn't really have to return it, if it sets a value to something that can be returned, but I guess i'm rusty enough with pointers that I can't seem to make this work. I've tried things that I think can't work, such as returning values, but i'm not sure what would go in this get function. </p> <pre><code> void Student::getName(char *fName, char *lName); { } int main() { char myFirstName[64] = "John" char myLastName[64] = "Doe" //testing to see if it's reading the char arrays correctly. cout &lt;&lt; "Your Name is:" &lt;&lt; myFirstName &lt;&lt; " " &lt;&lt; myLastName &lt;&lt; endl; Student aStudent; aStudent.setName(myFirstName, myLastName); //This part is where i'm confused. and i'm sure some above is confusing as well. getStudent = aStudent.getName(); } </code></pre> <p>I thought maybe I could return the private variable via the constructor, but why would I need a get function then? I'm just redoing this old assignment to get back into c++, I've been doing more network admin stuff, and ignored this for long enough to lose my mind apparently. Thanks in advance, and let me know if you need more information, I tried to be thorough.</p>
 

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