I've created a class, Category.
#ifndef CATEGORY_H_INCLUDED
#define CATEGORY_H_INCLUDED
#include <string>
using std::string;
enum Type {Integer, Double, Bool, String, Date, Time};
class Category
{
public:
Category() : itsType(String) {}
Category(Type type) : itsType(type) {}
Category(string name) : itsName(name) {}
Category(Type type, string name) : itsName(name), itsType(type) {}
~Category() {}
void operator=(const Category& rCat) {itsName = rCat.itsName; itsType = rCat.itsType;}
const Type& GetType() const {return itsType;}
const string& GetName() const {return itsName;}
private:
string itsName;
Type itsType;
};
#endif // CATEGORY_H_INCLUDED
Used in main.cpp.
#include <iostream>
using namespace std;
#include "Category.h"
int main()
{
Category test(String, string("Test"));
Category* pCat = new Category;
pCat[0] = test;
cout << "Name: " << pCat[0].GetName() << endl;
cout << "Type: " << pCat[0].GetType() << endl;
delete [] pCat; //Crashes the program
//delete pCat; //Works fine
return 0;
}
The problem is indicated in main().
When I use delete [] pCat
the program crashes.
When I do the same using delete pCat
, it doesn't.
If there's more than 1 Category in the array, the problem doesn't occur...
I've tried doing the same with int, which works fine. I can't seem to figure out why it doesn't work for Category..
Any input is welcome.