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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:19:51+00:00 2026-05-14T21:19:51+00:00

I am storing pointers to elements of a vec_A in an array A* a_ptrs[3]

  • 0

I am storing pointers to elements of a vec_A in an array A* a_ptrs[3] . Assume that vec_A will not be resized. So, a_ptrs[i] will point to the correct element.

My question is:

Suppose A* a_ptrs[3] is declared in a class B. Since it is not created using ‘new’ I am guessing I don’t need to delete it in the destructor. Am I right??

class A {
      public:                       
             int getNumber();            
             A(int val);
             ~A(){};
      private:
              int num;
};    
A::A(int val){
         num = val;
         };             
int A::getNumber(){
    return num;
};

 int main(){  
    int i  =0;
    int num;    
    std::vector<A> vec_A;
    for ( i = 0; i < 10; i++){
        vec_A.push_back(A(i));
        }

    A* a_ptrs[3];        
    a_ptrs[0] = &vec_A[0];        
    a_ptrs[1] = &vec_A[3];        
    a_ptrs[2] = &vec_A[5];

    for (i = 0; i<3; i++){
        std::cout<<"\n: a_ptrs[i].getNumber() = "<<a_ptrs[i]->getNumber();
    }        
    std::cout << "\nPress RETURN to continue...";
    std::cin.get();    
    return 0;
}
  • 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-14T21:19:52+00:00Added an answer on May 14, 2026 at 9:19 pm

    Yep, thats correct. You don’t need to use delete. The only issue is if the vector is resized e.g. by calling push_back etc – but you called that out in your post.

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

Sidebar

Related Questions

I am having some trouble storing some char pointers in my array The method
I'm trying to write a function that shifts all the elements in an array
I have a vector for storing the pointers of all objects (created by new
I am storing dynamically allocated class pointers in a vector like below. vector<Test *>
Storing credit card information securely and legally is very difficult and should not be
I am interested in allocating pointers, storing those in the LPARAM data of a
I have an array of char pointers in C with a size of 10.
gcc 4.6.2 c89 I have the following 2D array that I want to pass
Is there a way to cross over all elements in integer array using pointer
I am confuse on how to read the pointers copied in an array using

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.