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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:46:08+00:00 2026-06-05T10:46:08+00:00

I am trying to write this code where there are 2 classes inherited from

  • 0

I am trying to write this code where there are 2 classes inherited from a parent class.But this code breaks when I try to use it in a link list.Here is the code

class airship{

public:
    airship(){};
//  virtual ~ airship();
    virtual void setData (string)=0;
    virtual void showData()=0;
    void setNext(airship* newptr);
    airship* getNext();
    void setType(int n){airshipType=n;}
    int getType(){return airshipType;}
    void setCount(int n){maxPassengerCount=n;};
    int getCount(){return maxPassengerCount;}
    void setWeight(int n){maxCargoWeight=n;}
    int getWeight(){return maxCargoWeight;}

protected:
    int maxPassengerCount;
    int maxCargoWeight;
    int airshipType;

private:
    airship* next;
};

class airplane: public airship{

protected:

    const char* airplaneName;
    int engineType;
    double range;

public:
    airplane():airship(){};
//  ~ airplane();
    void setData(string);
    void showData();
    void setEngine(int n){engineType=n;}
    int getEngine(){return engineType;}
    void setRange(int n){range=n;}
    int getRange();

};

class balloon : public airship{

protected:
    const char* balloonName;
    int gasType;
    double maxAltitude;

public:
    balloon():airship(){};
//  ~balloon();
    void setData(string);
    void showData();
    void setGas(int);
    int getGas();
    void setAlt(int);
    int getAlt();

};

class mylist{

private:
    airship* headAirship;
public:
    void createlist(fstream&);
    void setAirship(airship* Node){Node=headAirship;}
    airship* getAirship(){return headAirship;}
};

void airship::setNext(airship* Node)
{
    this->next=Node;
}

void airplane::setData(string line)
{
    string line1;
    bool flag=true;
    int npos=0,nend,count=0;
    while(line.c_str()!=NULL && flag)
    {
        nend=line.find(",",npos);

        if (nend!=-1)
        {
            line1=line.substr(npos,nend);
        }
        else
        {
            line1=line;
            flag=false;
        }
        line=line.substr(nend+1,line.length());

        if (count==0)
            this->airshipType=atoi(line1.c_str());
        else if(count==1)
            this->airplaneName=line1.c_str();
        else if(count==2)
            this->maxPassengerCount=atoi(line1.c_str());
        else if(count==3)
            this->maxCargoWeight=atoi(line1.c_str());
        else if(count==4)
            this->engineType=atoi(line1.c_str());
        else
            this->range=atoi(line1.c_str());

        count=count+1;
    }
}

void balloon::setData(string line)
{
    string line1;
        bool flag=true;
        int npos=0,nend,count=0;
        while(line.c_str()!=NULL && flag)
        {
            nend=line.find(",",npos);

            if (nend!=-1)
            {
                line1=line.substr(npos,nend);
            }
            else
            {
                line1=line;
                flag=false;
            }
            line=line.substr(nend+1,line.length());

            if (count==0)
                this->airshipType=atoi(line1.c_str());
            else if(count==1)
                this->balloonName=line1.c_str();
            else if(count==2)
                this->maxPassengerCount=atoi(line1.c_str());
            else if(count==3)
                this->maxCargoWeight=atoi(line1.c_str());
            else if(count==4)
                this->gasType=atoi(line1.c_str());
            else
                this->maxAltitude=atoi(line1.c_str());

            count=count+1;
        }

}

void mylist::createlist(fstream &myfile)
{

    string ipdata;
    int type;

    while (getline(myfile,ipdata))
    {
            airship* newNode;
            type=ipdata.find(",",0);
            string ch=ipdata.substr(type-1,type);
            if (atoi(ch.c_str())==0)
            {
                airplane* planeNode=new airplane();
                planeNode->setData(ipdata);
                newNode=planeNode;
            }
            else
            {
                balloon* balloonNode=new balloon();
                balloonNode->setData(ipdata);
                newNode=balloonNode;
            }
            newNode->setNext(headAirship);
            this->headAirship=newNode;

    }


}


int main()
{
    mylist* list=0;
    airship* firstNode=0,*otherNode=0;

    /*if(argv[1]==NULL)
    {   
        cout<<"File not Found"<<endl;
        return -1;      
    }*/

    fstream ipFile("data.txt",ios::in | ios::out);

    if(ipFile.is_open())
    {
        list->createlist(ipFile);
    }

    list->setAirship(firstNode);


    return 0;
}

The airplane::setdata(string) function does not work properly and it is not able to detect headAirship pointer in the createList function.And that is why I get a memory exception error in the createlist function when I try to do this:newNode->setNext(headAirship);

Unhandled exception at 0x00912ae0 in Assignment4Solution2.exe: 0xC0000005:
Access violation reading location 0x00000000.

  • 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-05T10:46:10+00:00Added an answer on June 5, 2026 at 10:46 am

    I think the problem is here:

    mylist* list=0;
    

    In that line, you create a pointer to a myList object, but you don’t make it point to any such object; it’s pointing to address 0

    Then you do

    list->createlist(ipFile);
    

    Since list is not pointing an address containing a myList object, invoking any of the myList methods is supposed to give the error you observed: Access violation reading location 0x00000000.

    Instead, when you create the list pointer, invoke the constructor for myList so that the object gets created and the pointer is initialized to point to it

    myList * list = new myList();
    

    Hope that helps 🙂

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

Sidebar

Related Questions

I'm trying to write this code using mostly arrays. I'm trying to get Correct
I am trying to write a simple tool using Shoes. This will indent code
I'm trying to write a regular expression for html code that looks like this:
I am trying to write this method, which keeps reading from the user, until
any better way to write this ? $(this).parent().parent().find( dd ul).toggle(); update.. I am trying
I've been trying myself, and searching online, to write this regular expression but without
So I'm trying to write a base class to handle classes that wrap std::vector,
I've been trying to figure out how to write this regular expression. It is
I'm trying to write a calendar function like this function get_date($month, $year, $week, $day,
I'm trying to write a method like this: public static T Test<T>() { if

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.