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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:04:34+00:00 2026-05-15T22:04:34+00:00

I have created an abstract base class Animal which has public virtual abstract method

  • 0

I have created an abstract base class Animal which has public virtual abstract method makeSound(). I created a subclass Cow which implements Animal.makeSound() as you would expect (you know… “moo”). And I have a Farm class which holds a private member variable std::vector<Animal*> animals. In one of the Farm methods I iterate over all animals and make them make their sound.

for(unsigned int i = 0; i < animals.size(); i++)
{
   animals[i]->makeSound()
}

Unfortunately I get an error

Unhandled exception at 0x65766974 in
TestBed.exe: 0xC0000005: Access
violation reading location 0x65766974.

Any idea what’s going on here?


UPDATE: adding more code per request

class Farm
{
public:
    Farm();
    virtual ~Farm(void);

    void setBarnOnFire();

private:
    vector<Animal*> animals;
};


Farm::Farm()
{
    animals.push_back(new Dog());
    animals.push_back(new Cat());
    animals.push_back(new Chicken());
    animals.push_back(new Horse());
    animals.push_back(new Cow());
}



Farm::setBarnOnFire()
{
    for(unsigned int i = 0; i < animals.size(); i++)
    {
       animals[i]->makeSound()
    }
}

Is there something I’m supposed to do to initialize animals.

RESOLUTION:

So you were all correct. I was accessing memory that I didn’t own. But it took me forever to track it down. It was due to a misunderstanding about how object initialization takes place. Basically, in an effort to “initialize” a member variable I was actually overwriting it with a local variable. I then gave the local to all the animals that I created. Later, the animals would try to call the local variable – which no longer existed.

  • 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-15T22:04:35+00:00Added an answer on May 15, 2026 at 10:04 pm

    ok, let me take a guess:

    “Unhandled exception at 0x65766974 in TestBed.exe: 0xC0000005: Access violation reading location 0x65766974.”

    it seems that the code pointer is being sent to 0x65766974 (“exception at 0x65766974”) but this is not a valid place to be reading, let alone code: (“Access violation reading location 0x65766974”, note, the same number)

    so is it possible the vtable, or vtable pointer is being corrupted?
    perhaps the object is being overwritten by a string? as it is being stored in a vector, perhaps you have something overflowing a buffer (maybe a char array?) in the preceding object in the vector, and this is corrupting the next objects vtable pointer?

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

Sidebar

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.