Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:48:37+00:00 2026-06-08T19:48:37+00:00

I have a project I’m working on that’s actually a school project that I

  • 0

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

    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;
    }

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.

    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 << "Your Name is:" << myFirstName << " "  << myLastName << 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();

    }

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:48:39+00:00Added an answer on June 8, 2026 at 7:48 pm

    I would suggest you to use std::string instead of char arrays.

    So, your getName function should look like:

     std::string Student::getName()     {
        return firstName + lastName;
     }
    

    Using pointers and returning void can be done too, but is more difficult. Before calling the getName function, you have to allocate an array to keep the string. you code should look like:

    char firstName[100]
    char lastName[100];
    aStudent.getName(firstName, lastName);
    

    And your getName should look like:

    void Student::getName(char *fName, char *lName){
       strcpy(fName, firstName);
       strcpy(lName, lastName); 
    }
    

    First option is your way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have project which is currently working and was developed long time back on
I have project that I'm working on that is going to require a webserver.
I have project that concerns about calendars, at first i have 1 calendar and
I have project containing few user controls (each represents a game, but that's irrelevant),
I have project configured in Jenkins that polls an SCM and begins a build
I have project that consists of 8758 files. When I add them to my
I have a VS 2005/MSBuild 2.0 project (let's call it Project A) that I
I have project that shows few tables and try to use JQuery dialog boxes
I have project that creates dlls. These dlls are invoked from python later by
I have project that relies heavily on video and leverages html5 video when available.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.