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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:30:17+00:00 2026-06-10T13:30:17+00:00

C++ newb here. I’m trying to write my own implementation of an array using

  • 0

C++ newb here. I’m trying to write my own implementation of an array using only pointers, and I’ve hit a wall I don’t know how to get over.

My constructor throws this error

array.cpp:40:35: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]

When my array initializes I want it to free up all the spaces in the array for ints.

Array::Array(int theSize){
size = theSize;
int *arrayPointer = new int; 
int index = 0;
while(theSize > index){
  *(arrayPointer + index) = new int; //This is the trouble line.
  ++index;
 }
}

What am I doing wrong stackoverflow?

  • 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-10T13:30:18+00:00Added an answer on June 10, 2026 at 1:30 pm

    arrayPointer points to a single int, it does not point to an array of int*, which this line would require:

    *(arrayPointer + index) = new int;
    

    but the type of *(arrayPointer + index) is an int, hence the compiler error.

    To allocate an array of int:

    int* arrayPointer = new int[size];
    

    If this is intended to initialise a member variable then:

    arrayPointer = new int[size];
    

    otherwise arrayPointer would be local to the constructor. As the class now has a dynamically allocated member you need to either implement both copy constructor and assignment operator or prevent copying (see What is The Rule of Three?). Remember to delete[] arrayPointer in the destructor.


    Just mentioning std::vector<int>, even though this is a learning exercise.

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

Sidebar

Related Questions

Complete C newb here. Trying to learn/understand pointers by messing with simple code fragments.
Using Ruby (newb) and Regex, I'm trying to parse the street number from the
Python newb here. I m trying to count the number of letter as in
Jquery/programming newb here. I'm trying to dynamically assign a height to a ul to
iPhone/iPad dev newb here... I am using MonoTouch to create a universal iPad/iPhone storyboard
First post here so sorry if I seem like a newb, I am trying
jsfiddle demo Bear with me, total newb here. I'm trying to make a simple
Newb here trying to fix my php code. Getting an error at line 89.
LINQ-newb having trouble using grouping. I'm trying to query an IEnumerable called dosesWithHighestScore. I'm
I'm a very newb programmer trying to write some iOS programs, and when I

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.