qsorting an array of class pointers - c++

I've read a lot of material on how to do this. Unfortunately, they all resort to using something other than qsort (sort, usually). However, this is impossible for me as I'm not allowed to use anything from the algorithm library. I have to implement this from scratch, pretty much. What I've got:
class String {
public:
char* string;
int size;
String(char* string=0, int size=0) {
this->string = string;
this->size = size;
}
~String() {
delete [] string;
}
};
int compare(void* obj1, void* obj2) {
String* str1 = ((String*) obj1)->getColumn(column);
String* str2 = ((String*) obj2)->getColumn(column);
int i = strcmp(str1->string, str2->string);
delete str1;
delete str2;
return i;
}
class ArrayList {
int count;
int arraySize;
public:
String** list;
ArrayList() {
count = 0;
arraySize = 10;
list = new String*[arraySize];
}
~ArrayList() {
while(size()) {
delete remove();
}
}
void add(String* s) {
if(count==arraySize)
grow();
list[count++] = s;
}
String* remove() {
return list[count--];
}
String* get(int i) {
return list[i];
}
int size() {
return count;
}
private:
void grow() {
String** temp = new String*[arraySize*=2];
for(int i=0; i<count; i++) {
temp[i] = list[i];
}
delete [] list;
list = temp;
}
};
And my (current) call to qsort, though I've tried many combinations:
qsort(list->list, list->size, sizeof(String**), compare);
The error I ALWAYS get, not matter what I pass:
argument of type ‘int (ArrayList::)()’ does not match ‘size_t’
The code I've copied here doesn't include everything, but I've verified that all of the pieces work as intended, so don't worry about missing methods and such.

You have used list->size instead of list->size(). The code should be:
qsort(list->list, list->size(), sizeof(String**), compare);

Related

Dynamic Array resizing in C++ Doesn't work properly

i have this reSize function in my Array header
void reSize(int newsize) {
T* old = items;
size = newsize;
items = new T[newsize];
for (int i = 0;i < length;i++)
items[i] = old[i];
delete[]old;
}
and my main code:
struct User{
string name;
Array<int> data;
};
int main() {
Array<User> x(3);
x.get(0).name = "Kmal";
x.get(0).data.push_back(2); x.get(0).data.push_back(3);
x.reSize(10);
cout << x.get(0).data.get(0) <<endl;
return 0;
}
the problem is after resizing, my values that were stored in "data" variable are gone.
when i commented the code.
//delete[] old
in the reSize function
it worked fine...so i guess the problem is when i delete the pointer it deletes also the pointer inside the struct object which i don't want it to happen..
i don't want to comment the command becuz a leak in the memory will happen...how to fix this problem ?.
Update: My Array Class .
#include <iostream>
using namespace std;
template <class T>
class Array {
private :
T* items;
int size;
int length;
public :
Array() {
this->size = 0;
items = new T[this->size];
length = 0;
}
Array(int size) {
this->size = size;
items = new T[this->size];
length = 0;
}
int getsize() {
return this->size;
}
template <class T> void push_back(T x) {
if ((length+1) <= size) {
items[length] = x;
length++;
}
else {
this->reSize(size+1);
items[length] = x;
length++;
}
}
template <class T> void Insert(int index, T x) {
if (length + 1 <= size) {
for (int i = length;i > index;i--) {
items[i] = items[i - 1];
}
items[index] = x;
length++;
}
else {
this->reSize(size+1);
for (int i = length;i > index;i--) {
items[i] = items[i - 1];
}
items[length] = x;
length++;
}
}
template <class T> int Find(T x) {
int index = -1;
for (int i = 0;i < length;i++) {
if (items[i] ==x) {
index = i;
break;
}
}
return index;
}
void remove(int index) {
items[index] = "";
if(index+1 < length)
for (int i = index;i < length-1;i++) {
items[i] = items[i + 1];
items[i + 1] = "";
}
length--;
}
void reSize(int newsize) {
T* old = items;
size = newsize;
items = new T[newsize];
for (int i = 0;i < length;i++)
items[i] = old[i];
delete[]old;
}
void Merge(Array<T> x){
T* old = items; int oldlength = length;
items = new T[size + x.size];
size = size + x.size;
length += x.length;
for (int i = 0;i < length;i++) {
if(i< oldlength)
items[i] = old[i];
else
items[i] = x.items[i-oldlength];
}
delete[] old;
}
T& get(int index) {
return items[index];
}
}
struct User{
string name;
Array<int> data;
};
int main() {
Array<User> x(3);
// this line causes some problems
x.get(0).name = "Kmal";
x.get(0).data.push_back(2); x.get(0).data.push_back(3);
x.reSize(10);
cout << x.get(0).data.get(0) <<endl;
return 0;
}
In your code, declaring Array<User> x(3) declares an empty array with 3 elements that are preallocated. The length property of the array is 0. When the array is copied, length(0) elements are copied over into the resized storage. When you access the 0th element, it won't be copied on resize. What you actually need to do is call push_back() to add an element to the array so that length becomes 1 and the element is copied on resize.
Also, your array class is lacking a proper copy constructor and move constructor, which means copying it won't work at all. This means that User cannot be copied properly since it contains an array, which means that resizing an array of User won't work. You need to implement a copy constructor and copy assignment operator to be able to copy the array. You also need a destructor since, right now, the array is leaking memory when it goes out of scope.

Why is the overloading operator "=" not working properly on my class for Dynamic Arrays? C++

I'm trying to work with dynamic arrays. When I try to overload the "=" operator it does not work. When debugging the file it doesn't execute the void function to overload the operator.
#include <iostream>
using namespace std;
class cppArray {
public:
cppArray(int size);
~cppArray();
int read(int index);
void write(int content, int index);
void operator=(cppArray& s);
int search(int target);
int size();
private:
int* myArray;
int arraySize;
};
cppArray::cppArray(int size) {
myArray = new int[size];
arraySize = size;
}
//delete the memory space assigned to myArray
cppArray::~cppArray() {
delete[] myArray;
myArray = 0;
}
int cppArray::read(int index) {
if (index < arraySize) {
return myArray[index];
}
else {
cout << "Out of range" << endl;
exit(1);
}
}
Here I'm trying to copy the content of the original array to an auxiliar one, and then redefine the size of the original array so I can add more content to the original array
void cppArray::write(int content, int index) {
if (index < arraySize) {
myArray[index] = content;
}
else {
cppArray auxArray(arraySize);
auxArray.myArray = myArray;
delete[] myArray;
arraySize = index + 1;
myArray = new int[arraySize];
myArray = auxArray.myArray;
myArray[index] = content;
}
}
I'm pretty sure this is wrong, but I can't figure out a way to overload it correctly
void cppArray::operator=(cppArray& s) {
delete[] s.myArray;
s.myArray = new int[arraySize];
for (int i = 0; i < arraySize; i++)
{
myArray[i] = s.myArray[i];
}
}
int cppArray::size() {
return arraySize;
}
int main(int argc, char** argv) {
cppArray dsArray(3);
dsArray.write(1, 0);
dsArray.write(2, 1);
dsArray.write(3, 2);
dsArray.write(4, 3);
for (int i = 0; i < dsArray.size(); i++) {
cout << dsArray.read(i) << "\t";
}
cout << endl;
return 0;
}```
Your implementation is almost correct, but you delete the wrong array. You should only modify *this object, and not s. Also, you should follow conventions, or people will be very surprised when using your class.
Here's corrected version:
//return *this - a very expected convention
cppArray& cppArray::operator=(const cppArray& s) {
// Make sure s is not modified ^^^^
if (this == &s) {
return *this; //protection against self writing, things would get bad if you did that
}
arraySize = s.arraySize; //copy size first
delete[] myArray; //delete array from this object
myArray = new int[arraySize]; //recreate array
for (int i = 0; i < arraySize; i++)
{
myArray[i] = s.myArray[i]; //no changes here
}
return *this;
}

How to convert template T to a class pointer

I am trying to implement a template Array class that can hold pointers as well as primitive data types.
But when calling the destructor, the pointers in that array are not properly deleting.
So I am trying to convert each item in that array to its corresponding class and call delete. But I met with an issue. I'm not able to convert T type to my class pointer.
My intention is to delete items in that array. Can someone please help in this?
template <class T>
class LIBRARY_EXPORT MyArrayT
{
public:
MyArrayT()
{
this->count = 0;
}
~MyArrayT()
{
if ((this->count) > 0)
{
//std::cout << "Deleting Array values" << std::endl;
delete[] this->values;
//free(this->values);
/*for (int i = 0; i < this->count; i++)
{
delete this->values[i];
}*/
this->count = 0;
}
}
void SetValue(std::vector< T > items)
{
//Delete existing memory
delete[] this->values;
this->count = items.size();
if (this->count > 0)
{
this->values = new T[this->count];
for (int i = 0; i < count; i++)
{
this->values[i] = items[i];
}
}
}
void SetValue(T items, int index)
{
if (this->count > index)
{
this->values[index] = items;
}
}
T GetValue(int index)
{
if (this->count > index)
{
return this->values[index];
}
return NULL;
}
T* GetValue()
{
return this->values;
}
_int64 GetCount()
{
return this->count;
}
private:
_int64 count;
T* values;
};
class LIBRARY_EXPORT MyString
{
public:
MyString();
~MyString();
void SetValue(std::string str);
std::string GetValue();
_int64 GetCount();
private:
_int64 count;
char* value;
};
int main()
{
MyArrayT<MyString*>* MyArrayValue = new MyArrayT<MyString*>() ;
vector<MyString*> value9;
MyString* opt1 = new MyString();
opt1->SetValue("Option: 1");
value9.push_back(opt1);
MyArrayValue->SetValue(value9);
MyArrayT<int>* MyArrayValueInt = new MyArrayT<int>() ;
vector<int> value1;
value1.push_back(1);
value1.push_back(2);
MyArrayValueInt->SetValue(value1);
delete MyArrayValue; //Calling this delete doesn't calling the ~MyString() destructor
delete MyArrayValueInt;
}

How to initialize an array in private class without using a constant array size?

I have a header and .cpp file. I am having difficulty initializing the array. The problem is that I can't specify the array size. The size depends on the number of elements the user inputs. When I make a new dynamicArray, I believe I have to use the "new" like dynamicArray = new string[sizeof(array)] (because I have to delete the memory later according to the assignment) but when I run it through Linux, it says that it cannot appear in a constant - expression.
I'm still a little unfamiliar with C++. Any feedback is appreciated.
What the error looks like:
I also had issues with the header redefinition and I think the #pragma once helped.
I know #include "stdafx.h" is bad for linux. I remove it every time I run it on linux.
DynamaicStringArray.cpp
// DynamicStringArray.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "DynamicStringArray.h"
#include "Assignment9Test_V1.cpp"
// copy constructor that copies the array
DynamicStringArray::DynamicStringArray(string array[]) {
// string *dynamicArray = new string[sizeof(array)]; // without pointer, error with conversion between types
dynamicArray = new string[sizeof(array)];
for (int i = 0; i < sizeof(array); i++) {
dynamicArray[i] = array[i];
}
}
// default constructor
DynamicStringArray::DynamicStringArray() {
size = 0;
dynamicArray = NULL;
// dynamicArray = new string[size];
}
// frees up dynamic array memory
void DynamicStringArray::destructor(string array[]) {
delete[] array;
array = NULL;
}
// return number of entries in array
int DynamicStringArray::getSize() {
return size;
}
// creates a new dynamic array one element larger than dynamicArray
// copies all elements of dynamicArray to new array and
// add new string to end of new array
// increment size
// delete old dynamicArray
// set new array as dynamicArray
void DynamicStringArray::addEntry(string newString) {
string *newArray;
newArray = new string[size + 1];
for (int i = 0; i < size; i++) {
newArray[i] == dynamicArray[i];
}
int endIndex = sizeof(newArray);
newArray[endIndex] = newString;
destructor(dynamicArray);
dynamicArray = newArray;
}
// searches for dynamicArray for specific string,
// if string not found, return false
// if string is found, create new one size smaller dynamic array
// than dynamicArray
// copy elements of old dynamicArray to new array without the string
// delete old dynamicArray
// decrement size
// return true
bool DynamicStringArray::deleteEntry(string deleteMe) {
string *newArray;
newArray = new string[size - 1];
bool isFound = false;
for (int i = 0; i < size; i++) {
if (dynamicArray[i] == deleteMe) {
i++;
isFound = true;
}
else if (dynamicArray[i] != deleteMe) {
newArray[i] == dynamicArray[i];
}
}
if (isFound) {
return true;
destructor(dynamicArray);
dynamicArray = newArray;
}
else if (!isFound) {
return false;
}
}
// returns the string at that index
string DynamicStringArray::getEntry(int findMe) {
return dynamicArray[findMe];
}
DynamicStringArray.h
#pragma once
#include <string>
#include <iostream>
using namespace std;
class DynamicStringArray {
public:
DynamicStringArray();
DynamicStringArray(string array[]);
// overloading the assignment operator
void destructor(string array[]);
int getSize();
void addEntry(string);
bool deleteEntry(string);
string getEntry(int);
private:
int size; // holds number of entries in the array
string *dynamicArray; // references a dynamic array of type string
};
Your instinct to use new (specifically, new[] and delete[]) to solve this issue is correct. You must dynamically allocate the array at runtime since you don't know the number of elements at compile-time. However, you are not using new[]/delete[] correctly, which is why you are getting errors (amongst many other problems with your code).
Try something more like this instead:
DynamicStringArray.h
#pragma once
#include <string>
class DynamicStringArray {
public:
DynamicStringArray();
DynamicStringArray(const std::string *array, int arraySize);
DynamicStringArray(const DynamicStringArray &array);
~DynamicStringArray();
DynamicStringArray& operator=(const DynamicStringArray &array);
int getSize() const;
void addEntry(const std::string &newString);
bool deleteEntry(const std::string &deleteMe);
std::string getEntry(int findMe) const;
private:
int size; // holds number of entries in the array
string *dynamicArray; // references a dynamic array of type string
};
DynamicStringArray.cpp
// DynamicStringArray.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "DynamicStringArray.h"
// default constructor
DynamicStringArray::DynamicStringArray() {
size = 0;
dynamicArray = NULL;
}
// constructor that copies an array
DynamicStringArray::DynamicStringArray(const std::string *array, int arraySize) {
size = arraySize;
dynamicArray = new std::string[size];
for (int i = 0; i < size; i++) {
dynamicArray[i] = array[i];
}
}
// copy constructor that copies the array
DynamicStringArray::DynamicStringArray(const DynamicStringArray &array) {
size = array.size;
dynamicArray = new std::string[size];
for (int i = 0; i < size; i++) {
dynamicArray[i] = array.dynamicArray[i];
}
}
// frees up dynamic array memory
DynamicStringArray::~DynamicStringArray() {
delete[] array;
}
// copy assignment operator that copies the array
DynamicStringArray& DynamicStringArray::operator=(const DynamicStringArray &array) {
if (&array != this) {
DynamicStringArray copied(array);
std::string *temp = copied.dynamicArray;
copied.dynamicArray = dynamicArray;
dynamicArray = temp;
size = array.size;
}
return *this;
}
// return number of entries in array
int DynamicStringArray::getSize() const {
return size;
}
// creates a new dynamic array one element larger than dynamicArray
// copies all elements of dynamicArray to new array and
// add new string to end of new array
// increment size
// delete old dynamicArray
// set new array as dynamicArray
void DynamicStringArray::addEntry(const std::string &newString) {
std::string *newArray = new std::string[size + 1];
for (int i = 0; i < size; i++) {
newArray[i] = dynamicArray[i];
}
newArray[size] = newString;
delete[] dynamicArray;
dynamicArray = newArray;
++size;
}
// searches the dynamic array for a specific string,
// if string not found, return false
// if string is found, create new array one size smaller than dynamicArray
// copy elements of old dynamicArray to new array without the string
// delete old dynamicArray and replace with new array
// decrement size
// return true
bool DynamicStringArray::deleteEntry(const string &deleteMe) {
for (int i = 0; i < size; i++) {
if (dynamicArray[i] == deleteMe) {
std::string *newArray = new std::string[size - 1];
for (int j = 0; j < i; ++j) {
newArray[j] = dynamicArray[j];
}
for (int j = i+1; j < size; ++j) {
newArray[j-1] = dynamicArray[j];
}
delete[] dynamicArray;
dynamicArray = newArray;
--size;
return true;
}
}
return false;
}
// returns the string at that index
std::string DynamicStringArray::getEntry(int findMe) const {
return dynamicArray[findMe];
}
That being said, using a std::vector is the preferred solution. It is a dynamic-sized array that wraps new[]/delete[] for you. It is simpler and safer to use than using new[]/delete[] directly, eg:
DynamicStringArray.h
#pragma once
#include <string>
#include <vector>
class DynamicStringArray {
public:
DynamicStringArray();
DynamicStringArray(const std::string *array, int arraySize);
int getSize() const;
void addEntry(const std::string &newString);
bool deleteEntry(const std::string &deleteMe);
std::string getEntry(int findMe) const;
private:
std::vector<std::string> dynamicArray; // dynamic array of type string
};
DynamicStringArray.cpp
// DynamicStringArray.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "DynamicStringArray.h"
#include <algorithm>
// default constructor
DynamicStringArray::DynamicStringArray() {
}
// copy constructor that copies the array
DynamicStringArray::DynamicStringArray(const std::string *array, int arraySize) :
dynamicArray(array, array + arraySize) {
}
// return number of entries in array
int DynamicStringArray::getSize() const {
return dynamicArray.size();
}
// appends a new element to the end of the dynamic array
void DynamicStringArray::addEntry(const std::string &newString) {
dynamicArray.push_back(newString);
}
// searches the dynamic array for a specific string,
// if string not found, return false
// if string is found, remove it and return true
bool DynamicStringArray::deleteEntry(const std::string &deleteMe) {
std::vector<std::string>::iterator iter = std::find(dynamicArray.begin(), dynamicArray.end(), deleteMe);
if (iter != dynamicArray.end())
{
dynamicArray.erase(iter);
return true;
}
return false;
}
// returns the string at that index
std::string DynamicStringArray::getEntry(int findMe) const {
return dynamicArray[findMe];
}

c++ array class problems

Alright, so without going into detail on why I'm writing this class, here it is.
template<class aType>
class nArray
{
public:
aType& operator[](int i)
{
return Array[i];
}
nArray()
{
aType * Array = new aType[0];
_Size = 0;
_MaxSize = 0;
_Count = 0;
}
nArray(int Count)
{
aType * Array = new aType[Count*2]();
_Size = Count;
_MaxSize = Count * 2;
_Count = 0;
}
int Resize(int newSize)
{
aType *temp = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
temp[i] = Array[i];
}
delete[] Array;
aType * Array = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
Array[i] = temp[i];
}
delete [] temp;
_Size = newSize;
_MaxSize = newSize*2;
return 0;
}
int Push_Back(aType Item)
{
if(_Count+1 >= _Size)
{
Resize(_MaxSize);
}
Array[_Count] = Item;
_Count++;
return _Count - 1;
}
aType GetAt(int Index, int &ret)
{
if(Index > _Size-1)
ret = 1;
return aType();
ret = 0;
return Array[Index];
}
private:
int _Size;
int _Count;
int _MaxSize;
aType * Array;
};
It is supposed to be a std::Vector type object, without all the bells and whistles.
Problem is, it doesn't seem to work.
I basically start by going
nArray<string> ca = nArray<string>(5);
ca.Push_Back("asdf");
ca.Push_Back("asdf2");
int intret = 0;
cout << ca.GetAt(1,intret);
I get an Access Violation Reading Location error and it hits on the line
Array[_Count] = Item
in the Push_back function.
The problem seems to be that it's not treating the Array object as an array in memory.
I've spent time going through the code step by step, and I don't know what else to say, it's not operating right. I don't know how to word it right. I'm just hoping someone will read my code and point out a stupid mistake I've made, because I'm sure that's all it amounts to.
Update
So now I changed 3 initializations of Array in nArray(), nArray(int Count), and Resize(int newSize)
template<class aType>
class nArray
{
public:
aType& operator[](int i)
{
return Array[i];
}
nArray()
{
Array = new aType[0];
_Size = 0;
_MaxSize = 0;
_Count = 0;
}
nArray(int Count)
{
Array = new aType[Count*2]();
_Size = Count;
_MaxSize = Count * 2;
_Count = 0;
}
int Resize(int newSize)
{
aType *temp = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
temp[i] = Array[i];
}
delete[] Array;
Array = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
Array[i] = temp[i];
}
delete [] temp;
_Size = newSize;
_MaxSize = newSize*2;
return 0;
}
int Push_Back(aType Item)
{
if(_Count+1 >= _Size)
{
Resize(_MaxSize);
}
Array[_Count] = Item;
_Count++;
return _Count - 1;
}
aType GetAt(int Index, int &ret)
{
if(Index > _Size-1)
ret = 1;
return aType();
ret = 0;
return Array[Index];
}
private:
int _Size;
int _Count;
int _MaxSize;
aType * Array;
};
This is how my code was before. Anyway, the original problem was the fact that when I try to access a specific element in the array, it just accesses the first element, and it doesn't seem to add elements eather. It doesn't seem to be treating Array as an array.
int Resize(int newSize)
{
.
.
aType * Array = new aType[newSize*2];
At this point, instead of updating the member variable as you intended, you've actually created a local variable called Array whose value is discarded when you exit from Resize(). Change the line to
Array = new aType[newSize*2];
The same thing is happening in your constructors, they also need changing accordingly. Moreover, since the default constructor allocates an array, you should set the size members accordingly. You have too many of these: an array needs to keep track of current element count and maximum capacity, however you appear to have three members. What is the purpose of the third? Redundant information is bad, it makes code difficult to read and without a single point of truth it is easier to make mistakes.
With the code in Resize(), you can do better: the second copy is completely redundant.
int Resize(int newSize)
{
aType *temp = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
temp[i] = Array[i];
}
delete[] Array;
Array = temp;
_Size = newSize;
_MaxSize = newSize*2;
return 0;
}
Also, in
aType GetAt(int Index, int &ret)
{
if(Index > _Size-1)
ret = 1;
return aType();
ret = 0;
return Array[Index];
}
you need curly braces around body of the if(), just indentation on its own won't do the trick:
aType GetAt(int Index, int &ret)
{
if(Index > _Size-1)
{
ret = 1;
return aType();
}
ret = 0;
return Array[Index];
}
You have a number of problems. At a guess, the one causing problems so far is that your default ctor (nArray::nArray()) defines a local variable named Array that it initializes, which leaves nArray::Array uninitialized.
Though you probably haven't seen any symptoms from it (yet), you do have at least one more problem. Names starting with an underscore followed by a capital letter (such as your _Size, _MaxSize, and _Count) are reserved for the implementation -- i.e., you're not allowed to use them.
The logic in your Resize also looks needlessly inefficient (if not outright broken), though given the time maybe it's just my brain not working quite right at this hour of the morning.
Your array is not initialized by the constructors and resize function (working on local vars instead).
And is there a reason you want to store instances of string and not pointers to string (string *) ?
I think the answer after the changes is in moonshadow's reply:
aType GetAt(int Index, int &ret)
{
if(Index > _Size-1)
ret = 1;
return aType();
ret = 0;
return Array[Index];
}
This code will always return aType(), the last two lines will never be reached.
You might also want to check what happens if you start out with a default-constructed nArray. (Hint: you call Resize(_MaxSize); but what is the value of _MaxSize in this case?
Edit:
This outputs "asdf2" for me as it should be (with the initialization and the braces fixed):
template<class aType>
class nArray
{
public:
aType& operator[](int i)
{
return Array[i];
}
nArray()
{
Array = new aType[0];
_Size = 0;
_MaxSize = 0;
_Count = 0;
}
nArray(int Count)
{
Array = new aType[Count*2]();
_Size = Count;
_MaxSize = Count * 2;
_Count = 0;
}
int Resize(int newSize)
{
aType *temp = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
temp[i] = Array[i];
}
delete[] Array;
Array = new aType[newSize*2];
for(int i=0;i<_Count;i++)
{
Array[i] = temp[i];
}
delete [] temp;
_Size = newSize;
_MaxSize = newSize*2;
return 0;
}
int Push_Back(aType Item)
{
if(_Count+1 >= _Size)
{
Resize(_MaxSize);
}
Array[_Count] = Item;
_Count++;
return _Count - 1;
}
aType GetAt(int Index, int &ret)
{
if(Index > _Size-1) {
ret = 1;
return aType();
}
ret = 0;
return Array[Index];
}
private:
int _Size;
int _Count;
int _MaxSize;
aType * Array;
};
#include <string>
#include <iostream>
using namespace std;
int main()
{
nArray<string> ca = nArray<string>(5);
ca.Push_Back("asdf");
ca.Push_Back("asdf2");
int intret = 0;
cout << ca.GetAt(1,intret);
}