throwing an instance of error ..? help

Okay so i made a program to create an 2-dimensional array however everytime i run it, it happens to throw an instance of 'ARRAY ERRRORS'. Im not sure why it has that when my inputs are defintely not array errors or whatever i put in it gives array errors. if anything i wish i could have the made the program show me what type of array errors rather than implicting saying ARRAY ERRORS.


#ifndef SMARTARRAY_H
#define SMARTARRAY_H
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <iomanip>


enum ARRAY_ERRORS {OUT_OF_BOUNDS, NEGATIVE_SIZE, BAD_DIMENSION, CANNOT_RESIZE};
enum ARRAY_SORT {ASCENDING, DESCENDING};

using namespace std;

class smartArray
{
public:
smartArray(int s = 5, int v = 0);
~smartArray();
smartArray(const smartArray &other);
smartArray& operator=(const smartArray &other);

int& operator[](int index);
void resize(unsigned int newSize);
unsigned int size();
unsigned int find(int x);
int min() const;
int max() const;
double average();
double stdev();
double var();
double median();
void initialize(int x = 0);
void swap(smartArray &other);
void sort(ARRAY_SORT order = ASCENDING);
void reverse();

friend
ostream& operator<<(ostream &out, const smartArray &list);

friend
istream& operator>>(istream& in, smartArray& list);

private:
int *list;
unsigned int mySize;

void copy(const smartArray& other);
void nukem();
void swap(int &x, int &y);
bool whichSort(ARRAY_SORT order, int x, int y);

};

#endif // SMARTARRAY_H

smartarray.cpp

#include "smartarray.h"

smartArray::smartArray(int s, int v)
{
if(s < 1)
{
throw BAD_DIMENSION;
}
list = new int[mySize = s];
initialize(v);
}

smartArray::~smartArray()
{
nukem();
}

smartArray::smartArray(const smartArray &other)
{
copy(other);
}

smartArray& smartArray::operator=(const smartArray &other)
{
if(this != &other)
{
nukem();
copy(other);
Last edited on
From your code it is not possible to tell what the problem is. How do you produce this error?

Do not throw something like enum ARRAY_ERRORS.

If you want to throw inherit from std::exception:

http://www.cplusplus.com/reference/exception/exception/

As you can see there are already exception that describe the problem.

Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.