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 8369509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:39:48+00:00 2026-06-09T13:39:48+00:00

Everything in my coding works except the get and set name functions. When I

  • 0

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.

Here is my .cpp file.

#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>

#include "Student.h"

using namespace std;

int main()
{
    //for student name
    string firstName;
    string lastName;
    string fullName;


//student name

cout << "Please enter your students first name" << endl;
cin >> firstName;
cout << "firstName = " << firstName << endl;


cout << "Please enter your students last name" << endl;
cin >> lastName;
cout << "lastName = " << lastName << endl;

aStudent.setName(firstName, lastName);
fullName = aStudent.getName();

cout << "Your students name is : ";
cout << fullName << endl;

}
#endif

Here are my functions, and class, .h file.

#include <iostream>
#include <string>
#include <conio.h>

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;
}
  • 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-09T13:39:50+00:00Added an answer on June 9, 2026 at 1:39 pm
    void Student::setName(std::string firstName, std::string lastName)
    {
        firstName = fName;
        lastName = lName;
    }
    

    Surely you see the problem there. Hint, assignment copies the thing on the right to the thing on the left.

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

Sidebar

Related Questions

I am working on some form coding in PHP, and I have everything working
Everything is working fine until I call the saveFile method (shown below) to write
In my document i'm using the package glossaries to create a glossary. Everything works
Everything works, but this is just to know the correct practice/right approach/what makes sense
I'm coding my first app targeting ICS (4.0.3 - level 15). I get Action
This is a security issue I'm trying to figure out. Everything works fine and
- Bref history: - I was using MapServer, everything was working fine except that
I'm working on the n'th application locating zip's. Everything works fine in PHP while
I have successfully completed, and no problems with the program, everything works just fine,
I cannot figure out a relative path that works for my resource. I've tried

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.