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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:32:24+00:00 2026-06-07T19:32:24+00:00

I created a vector with Pointers and I create new Objects from the class

  • 0

I created a vector with Pointers and I create new Objects from the class DigOut derived from Modul in one method called

BOOL Cbeckhoff_frontendDlg::OnInitDialog()
{
//...
std::vector<Modul*> arrDigOut;
arrDigOut.push_back(new DigOut(IDC_CHECK1, this,"GVL.DigOut1",pAddr));
//...
for(iNumDO = 0;iNumDO<1;iNumDO++) arrDigOut[iNumDO]->InitCheck(this);
//...
}

How can I access the vector from a different method like:

void Cbeckhoff_frontendDlg::OnBnClickedButton3()
{
for(iNumDO = 0;iNumDO<1;iNumDO++) arrDigOut[iNumDO]->SetID();
}

I thought about using public pointers or setters and getters,
but I don’t get to create membervariables like this:

std::vector<Modul*> *   parrDigOut;

where it’s complaining, that Modul is not declared.

  • 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-07T19:32:26+00:00Added an answer on June 7, 2026 at 7:32 pm

    Your example gives the impression you are declaring the vector at function scope. Its lifetime ends at the end of the function call (and all memory is leaked). Store it as a class member and a member functions begin and end that forward to the begin and end member functions of the vector. Possibly wrap them in a dereference_iterator to hide the fact that they are pointers.

    class foo {
    public:
      foo() { 
        // add things to s_
      }
    
      ~foo() { 
        // dont forget to delete everything in s_
      }
      typedef std::vector<my_stuff*>::iterator iterator;
      typedef std::vector<my_stuff*>::const_iterator const_iterator;
      iterator begin() { return s_.begin(); }
      iterator end() { return s_.end(); }
      const_iterator begin() const { return s_.begin(); }
      const_iterator end() const { return s_.end(); }
    
      // or to hide the pointers
      typedef boost::indirect_iterator< std::vector<my_stuff*>::iterator > iterator;
      iterator begin() { return boost::make_indirect_iterator(s_.begin()); }
      iterator end() { return boost::make_indirect_iterator(s_.end()); }
    private:
      std::vector<my_stuff*> s_;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector for storing the pointers of all objects (created by new
I have a vector of pointers to objects created with new . Multiple threads
I am attempting to store objects derived from a templated base class in an
I created a vector of pointers vector<Person*> *personVec = new vector<Person*>(); Person contains: getName();
For my latest CS homework, I am required to create a class called Movie
I am trying to create a vector that contains pointers, each pointer points to
So I have a vector of pointers holding a baseclass. I create two elements
I want to have a deep copy of an vector with pointers to objects,
I have a base class which has two child classes derived from it. class
I am writing a server in C++ and created a class called client to

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.