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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:36:54+00:00 2026-05-16T06:36:54+00:00

This semester in university I have a class called Data Structures, and the professor

  • 0

This semester in university I have a class called Data Structures, and the professor allowed the students to choose their favourite language. As I want to be a game programmer, and I can’t take Java anymore, I chose C++ … but now I’m stuck with lack of knowledge in this language. I have to do the following: create a SuperArray, which is like a Delphi array (you can choose the starting and ending index of it). My code is as follows:

main.cpp

#include <iostream>
#include "SuperArray.h"    

using namespace std;

int main(int argc, char** argv) 
{
    int start, end;
    cout << "Starting index" << endl;
    cin >> start;
    cout << "Ending index:" << endl;
    cin >> end;
    SuperArray array = new SuperArray(start,end); 
}

superarray.h

#ifndef _SUPERARRAY_H
#define _SUPERARRAY_H

class SuperArray
{
public:
    SuperArray(int start, int end);
    void add(int index,int value);
    int get(int index);
    int getLength();
private:
    int start, end, length;
    int *array;

};

#endif  /* _SUPERARRAY_H */

superarray.cpp

#include "SuperArray.h"

SuperArray::SuperArray(int start, int end)
{
    if(start < end)
    {
        this->start = start;
        this->end = end;
        this->length = (end - start) + 1;
        this->array = new int[this->length];
    }
}

void SuperArray::add(int index, int value)
{
    this->array[index-this->start] = value;
}

int SuperArray::get(int index)
{
    return this->array[index-this->start];
}

When I try to compile this code, I have the following error:

error: conversion from `SuperArray*' to non-scalar type `SuperArray' requested

What should I do?

  • 1 1 Answer
  • 1 View
  • 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-16T06:36:55+00:00Added an answer on May 16, 2026 at 6:36 am

    Unlike Java, in C++ you don’t need to use the new keyword to create objects. In Java, all objects are stored on the heap (free store) and can only be accessed via references.

    In C++, objects can be value types. You can declare them directly on the stack, e.g.

    SuperArray array(start, end);
    

    And you can call methods like:

    array.get(1);
    

    This object will be automatically destroyed when array goes out of scope. If you want to manage the lifetime of the array object manually, you can optionally create it on the heap using new, but then you have to refer to it with a pointer:

    SuperArray* array = new SuperArray(start, end);
    

    Now, you must call methods like this:

    array->get(i);
    

    since array in this case is a pointer to a SuperArray and not a SuperArray itself (and a pointer has no get method of its own). The -> operator means to use the . operator on the pointed-to object.

    In this case, the object pointed to by the array pointer will continue to exist until you call delete array; If you fail to explicitly delete the object, it will never be deallocated (C++ has no garbage collector!) and you will have a memory leak.

    Note that C++ has things called “pointers” and things called “references”. A Java “reference” has some of the properties of both of these things and is not directly equivalent to either. A good introductory text on C++ should explain the difference between these.

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

Sidebar

Related Questions

I'm teaching a data structures class this semester and we build gobs of JUnit
I have this class public class Subject { int ID; string Name; int Semester;
This semester I'm teaching a class at a local university. Thus far, I've had
I have experience programming in C#, but I'm taking a C++ class this semester,
I'm taking a class on Flex/Bison at University this semester, and I'm having serious
I am taking a C programming class this semester, and was somehow allowed to
This should be a simple one: I have an observableArray object called To in
I'm teaching a new course at a new University this semester, and I'm really
Intro We have a project to design and implement this semester. For our project,
I have a table which stores the courses registered by students during a semester

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.