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

  • Home
  • SEARCH
  • 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 3229656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:50:10+00:00 2026-05-17T16:50:10+00:00

I am learning C++ and i currently have some questions that i don’t know

  • 0

I am learning C++ and i currently have some questions that i don’t know the answers. I create this header file Object1.h and can compile this file but when i run the Test.cpp, Visual Studio throw an error because of access violation by *sibling. The strange thing is I can run it using Dev C+ and it return only value 2.Therefore I want to ask why assigning *sibling will create an error and why i can’t change Person B’s address using setAddress(). I will really appreciate if any one can give me some answer or hints. Thanks in advance.


//This is Object1.h
#include <iostream>
using namespace std;

class Person{
public:
    Person(int ID);
    void setAddress(string addr);
    string getAddress();
    void addSibling(Person *p);
    Person getSibling();
    int ID;
private:    
    string address;
    Person *sibling;
};

Person::Person(int ID){
    this->ID = ID;
}

void Person::setAddress(string addr){
    this->address = addr;
}

string Person::getAddress(){
    return address;
}

void Person::addSibling(Person *p){
    *sibling = *p;
}

Person Person::getSibling(){
    return *sibling;
}

//This is Test.cpp
#include <iostream>
#include <string>
#include "Object1.h"
using namespace std;

int main(){
    Person A(1);
    Person B(2);
    A.addSibling(&B);
    // Change the address of person B through person A's getSibling()
    A.getSibling().setAddress("123 Street");

    cout << B.getAddress() <<endl;
    cout << B.ID;

    system("Pause");
    return 0;
}
  • 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-17T16:50:10+00:00Added an answer on May 17, 2026 at 4:50 pm

    Using operator * assumes that you deal with some data resided by address stored in this variable. Let’s review your code:

    *sibling = *p;
    

    You trying to copy by value. This is wrong because sibling points to nowhere. It is even not a NULL, it is unpredictable. The correct line will be:

    sibling = p;
    

    So you tell that would store pointer to another instance.

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

Sidebar

Related Questions

im currently learning python (in the very begining), so I still have some doubts
I am currently learning Perl. I have Perl hash that contains references to hashes
I am currently learning C# and LINQ. I have lots of questions about them.
I'm currently learning C++ and there are some (basic) things which I don't really
I am currently learning data mining and I have the following questions. what is
I have some code that reads a file into an array of lines, and
I am currently learning F# and have tried (an extremely) simple example of FizzBuzz.
im currently learning stacks in java and have a quick question. what will the
I am currently learning about basic networking in java. I have been playing around
Learning Scala currently and needed to invert a Map to do some inverted value->key

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.