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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:31:55+00:00 2026-05-20T15:31:55+00:00

I have been a follower for a long time but this is the first

  • 0

I have been a follower for a long time but this is the first time I ask a question. In a nutshell, the issue is; vector<Student*> studentvector that is a vector of object pointers seems to push the student info back as student ; but when I print to see the first one in vector whether it performs as intended, I see it always updates the first record with new coming student info although there is no problem on studentvector.size() It pushes the record back to the vector as many as how many time I call addStudent(...) but it fills all vector with the information of last student. What may be done to succeed in filling vector with correct info within this frame, without using smart pointers or advanced stuff?

Sorry if I am vague on my question. You may lead me to provide what is also necessary to understand the problem. Thanks in advance.

addStudent(const string alias, const string name) throw(StudentException)
{
Student* student = new Student(alias, name)
studentvector.push_back(student);
cout << studentvector.front() << endl;
}

That is the implementation of Student;

#include "Student.h"

string *Alias;
string *Name;


Student::Student(string alias)
{
    Alias = new string(alias);
}

Student::Student(string alias, string name)
{
    Alias = new string(alias);
    Name = new string(name);
}

Student::~Student()
{
    delete Alias;
    delete Name;
}

const string& Student::getAlias() const
{
    return *Alias;
}

void Student::setAlias(const string& alias)
{
    *Alias = alias;
}

const string& Student::getName() const
{
    return *Name;
}

void Student::setName(const string& name)
{
    *Name = name;
}

Consider alias is not reserved.

  • 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-05-20T15:31:56+00:00Added an answer on May 20, 2026 at 3:31 pm

    Doh! Here’s your problem – all objects from type Student use the same global pointers:

    string *Alias;
    string *Name;

    Make these two as members in you class

    
    class Student
    {
    private:
        string *Alias;
        string *Name;
    //..
    }; 
    

    EDIT:
    Also, I don't think, that it's a good idea to use pointer to std::string, I'd suggest you to use like this:

    class Student
    {
    private:
        string Alias;
        string Name;
    //..
    }; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking at this for a long time and finally decided to
Have been working on this question for a couple hours and have come close
I have been messing with this for quite some time now and it's getting
I've been looking at this issue for too long. I suspect I'm missing something
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have been searching how to convert a dictionary to a string. But the results
I have been trying to register 3 hotkeys. I followed this example (or this
first of all sorry if this isn't formatted correctly, first time doing this. I've
There have been a lot of discussion around this and everyone tend to agree
I have been having a very difficult time editing my .htaccess file to do

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.