Hi! 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?