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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:24:01+00:00 2026-05-16T21:24:01+00:00

In my C++ project, I have a class App, and a class Window. Class

  • 0

In my C++ project, I have a class App, and a class Window. Class App has a parameter: vector<Window*>* window;.

In App’s constructor, it is able to use and push_back a Window* onto this vector fine, but in my onMessage() method, which is called by the WndProc() (I’m using winapi), it gives me an runtime error when I try to use the vector. These are access errors.

What on earth could be going wrong? If you need any more info, just ask.

  • 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-16T21:24:02+00:00Added an answer on May 16, 2026 at 9:24 pm

    Either the pointer to the vector is invalid or the pointers in the vector are invalid; probably the former in this case. This happens in many situations, such as using pointers to local objects which have since been destroyed.

    (Aside: Given that you included a semicolon for window, I bet this is a data member rather than a parameter.)

    Instead of storing a vector pointer in App, store a vector itself. Instead of storing pointers to Window objects, store the Window objects themself.

    struct App {
      vector<Window> windows;
    };
    

    However, this requires Windows to be Copyable, and they probably aren’t. It also disallows storing objects of types derived from Window. Instead, you can use a boost::ptr_vector, which “owns” the pointed-to objects and will delete them when they are erased (such as when the ptr_vector is destroyed or cleared):

    struct App {
      boost::ptr_vector<Window> windows;
    
      App() {
        // just an example
        windows.push_back(new Window());
        windows.push_back(new DerivedFromWindow());
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a C# class library and a startup project (a console app). The
I have inherited a project that has class libraries written in VB.NET, some of
In my project I have a class that is inherited by many other classes.
I'm using the SQLAlchemy Python ORM in a Pylons project. I have a class
I have a generic class in my project with derived classes. public class GenericClass<T>
I have been working on a Java project for a class for a while
I have a Windows Service project, A, with a dependency on a class library
I have a .NET 2.0 windows forms app, which makes heavy use of the
I have an Xcode project with the following group structure: ProjectName/ Classes/ class1.h class1.m
I have an solution in VS 2008 which contains two class library projects and

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.