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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:22:36+00:00 2026-06-14T16:22:36+00:00

Hello I am having trouble with using dynamic arrays within a class. I am

  • 0

Hello I am having trouble with using dynamic arrays within a class. I am instructed that “the class VectorDouble will have a private member variable for a dynamic array of doubles.” I am only as far as writing the header file for this program, but I have not gotten past that. This class needs to be able to double in size once it has reached capacity.
Here is my code:

#include <iostream>
using namespace std;

// VectorDouble class header file
class VectorDouble
{
    public:
    // constructor for an empty vector of type double
        VectorDouble();
    // constructor that take an int argument for an integer size of and array
        VectorDouble(int initial_size);
    // copy constructor
        VectorDouble(VectorDouble &object);
    // destructor to return dynamic memory to the freestore
        ~VectorDouble();
    // overloaded operator = for VectorDouble class
        VectorDouble& operator =(const VectorDouble &source);
    // overloaded operator == for VectorDouble class
        friend bool& operator ==(const VectorDouble &this_vector,
                                 VectorDouble &other_vector);
    // adds a new element at the end of the array
        void push_back();
    // returns allocated size of VectorDouble dynamic array
        int capacity();
    // returns used size of the VectorDouble object
        int size();
    // allocates a specified block of memory for specified number of double
    // type values
        void reserve(int new_reserve);
    // changes the size of the dynamic array
        void resize(int new_size);
    // returns the value at the specified index
        double value_at(int index);
    // changes the value at the specified index to double value d
        void change_value_at(double d, int index);

    private:

        int count;
        int max_count;
        int index_pointer;
        *index_pointer = new double[100]; 

}; 

The errors I am getting are all on this line:*index_pointer = new double[100];

  • `new’ cannot appear in a constant-expression

  • ISO C++ forbids declaration of `index_pointer’ with no type

  • ISO C++ forbids initialization of member `index_pointer’

  • making `index_pointer’ static

  • invalid in-class initialization of static data member of non-integral
    type `int*’

  • 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-14T16:22:38+00:00Added an answer on June 14, 2026 at 4:22 pm

    Your pointer needs a type. Change that line to

    double* index_pointer;
    

    And in your constructor add the line

    index_pointer = new double[100];
    

    And so on for your other constructors and assignment operator.

    But this is also a naming conflict because you have another private int member named index_pointer. I’m not sure what that member is for, but if you do actually need it then you’ll have to name it or the pointer something else.

    Remember to delete[] index_pointer; in your destructor.

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

Sidebar

Related Questions

Hello I have been having trouble with this for a while now. I have
Heloo, I'm having trouble with overloading the / operator in a member function within
Hello I am having trouble using multiquery in facebook .net. I am trying to
I'm having trouble getting a simple Hello World app to work using Flask, MongoDB,
Hello I'm having trouble figuring this out. I have these structs and classes. struct
Hello I am having trouble with a xml file I am using. Now what
Hello I am having trouble with a xml file I am using. Now what
Hello I am having trouble getting my Python to work correctly. I have a
Hello trying to get my website to display correctly having trouble. I am using
Hello I'm having trouble with the following piece of code: <h:selectOneMenu id=selectTipoAutorizacion value=#{autorizacion.codigoTipoAutorizacion} required=true>

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.