My take on your requirements:
#include <iostream>
#include <vector>
#include <stdexcept>
using namespace boost;
using namespace std;
class MyClass
{
public:
MyClass(int Size) : Size_(Size)
{
Data_.resize(30 * 30 * Size_);
}
int* & operator()(int x, int y, int z)
{
if (x < 0 || x >= Size_ || y < 0 || y >= 30 || z < 0 || z >= 30)
throw out_of_range("Coord out of range");
return Data_[ z + (30 * y) + (30 * 30 * x) ];
}
int Size() const
{
return Size_;
}
private:
vector<int*> Data_;
int Size_;
};
void my_test_func(const MyClass& X);
int main()
{
MyClass X(10);
X(1, 20, 20) = new int(10);
int* y = X(1, 20, 20);
cout << "y = " << y << endl;
cout << "*y = " << *y << endl;
my_test_func( X );
return 0;
}
void my_test_func(const MyClass& X)
{
MyClass MyCopy( X ); // Uses the default copy constructor
}
Avoid all of that low-level memory nonsense - use a vector. Then you don't need to get the copy constructor, operator= or destructor correct.