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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:48+00:00 2026-05-23T16:55:48+00:00

I generally avoid using class pointers , since references seem way more efficient. But

  • 0

I generally avoid using class pointers , since references seem way more efficient. But I have been recently forced to use them as they present the only (efficient and easy) solution to binding functions with window ids in my windows api wrapper. I have created an array of class WinControl. in my WinHandler class which handles the WndProc (Window Procedure) and add all the widgets used in the program to that array.

class WinControl   //These are not the entire classes, just the significant parts.
{
    public:
        int WinID;
        virtual void Click(void) = 0; //Pure Virtual Function.
}

class WinHandler
{ 
    WinHandler() : WCount(0) { }
    WinControl* WidgetSet[MAX_LENGTH];   // Or I can use an STL vector...
    int WCount;
    void AddWidget(Widget* w) { WCount++; WidgetSet[WCount] = w; }
}         

Then then I use:

if (WidgetSet[i]->ID == LOWORD(wParam)) WidgetSet[i]->Click();

Will this approach be alright in the long run? As the Objects actually stored in the WidgetSet will all be derivatives of class WinControl. Can anyone suggest a better approach?

NOTE: I have tried to make my question as clear as possible. If u still can’t get what I am asking, please comment and I will try to elaborate the question.

  • 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-23T16:55:49+00:00Added an answer on May 23, 2026 at 4:55 pm

    What you are storing in the widget set is a pointer. NOT the object. The problem with your design is that it is not clear who is supposed to own the object thus destroy it.

    I would change the interface to make ownership explicit.

    Option 1:

    WinHandler does NOT own the widget:

    void AddWidget(Widget& w) { WCount++; WidgetSet[WCount] = &w; }
    

    Option 2:

    WinHandler Takes ownership of the widget

    void AddWidget(std::auto_ptr<Widget> w) { WCount++; WidgetSet[WCount].reset(w); }
    std::auto_ptr<WinControl> WidgetSet[MAX_LENGTH];
    

    Option 2a:

    (for those with newer compilers)
    WinHandler Takes ownership of the widget

    void AddWidget(std::unique_ptr<Widget>& w) { WCount++; WidgetSet[WCount] = std::move(w); }
    std::unique_ptr<Widget> WidgetSet[MAX_LENGTH];
    

    Option 3:

    (for those with newer compilers)
    WinHandler shares ownership of the widget

    void AddWidget(const std::shared_ptr<Widget>& w) { WCount++; WidgetSet[WCount] = w; }
    std::shared_ptr<Widget> WidgetSet[MAX_LENGTH];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Generally I connect and retrieve data using the standard way (error checking removed for
I've generally heard that production code should avoid using Lazy I/O. My question is,
I constantly hear how bad reflection is to use. While I generally avoid reflection
Generally when I use ClickOnce when I build a VB.NET program but it has
Generally the database server is the biggest, most expensive box we have to buy
Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
Generally, when using the conditional operator, here's the syntax: int x = 6; int
I'm using the Boost::Test library for unit testing, and I've in general been hacking
http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/ I have been about this lately to review C++. In general computing class
I'm using VS2008 to build a plain old C++ program (not C++/CLI). I have

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.