ForumNorway.com Forum Index ForumNorway.com

 
Log in to check your private messagesLog in to check your private messages

Log inLog in  RegisterRegister


Profile  Search  Memberlist  FAQ  Usergroups
An ARR3D class implemented as a pointer to a pointer pointer

 
Post new topic   Reply to topic    ForumNorway.com Forum Index -> C++
View previous topic :: View next topic  
Author Message
KBleivik
Site Admin


Joined: 31 Jan 2006
Posts: 78
Location: Moss Norway

PostPosted: Fri Sep 22, 2006 4:55 pm    Post subject: An ARR3D class implemented as a pointer to a pointer pointer Reply with quote

/*

The Matrix class is inspired by Bjarne Stroustrup "The C++ programming Language
Second Edition" Addison-Wesley Publishing Company 1992 page 236, Ira Pohl
"Objectoriented programming in C++" Benjamin/Cummings Publishing Company, Inc.
1993 page 256 -> and Andrew Koenig "Multidimensional arrays and new-expressions"
C++ Report February 1994 page 52.

*/
#include <iostream.h>
#include <assert.h>

enum boolean{false, true};

template <class Type> class Stack;
template <class Type> class Iterator;
template <class Type> class Arr3d
{
private:
int dim1, dim2, dim3;
Type ***p; // Pointer to pointer to pointer.
friend class Iterator<Type>;
friend class Stack<Type>;
public:
Arr3d(){ // Default constructor.
dim1=dim2=dim3; // 3x3x3 Identity Array is default.
p={{1,0,0},{0,1,0},{0,0,1}};
}
Arr3d(int d1, int d2, int d3); //Parameterized constructor type 1.
Arr3d(const Type a[], int d1, int d2,int d3); //Parameterized constructor type 2. Array
//initialization.
Arr3d(const Arr3d& m); // Copy constructor
~Arr3d(); // Destructor.
Arr3d& operator()(int i1, int i2, int i3) { return(p[i1][i2][i3]);}
};
/*
Matrix& operator=(const Matrix& m);
Matrix& operator+=(const Matrix& m);
Matrix& operator*=(const Matrix& m);
friend Matrix operator+(const Matrix&, const Matrix&);
friend Matrix operator*(const Matrix&, const Matrix&);
};

template<class Type>
Matrix<Type>::Matrix(int c, int r) : cSize(c), rSize(r)
{
p = new Type*[c]; // Array of pointers to double
for (int i = 0; i < c; ++i)
p[i] = new double[r];
}
template<class Type>
Matrix<Type>::~Matrix()
{
for (int i = 0; i < cSize; ++i)
delete [] p[i];
delete [] p;
}

template<class Type>
Matrix<Type>& Matrix<Type>::operator=(const Matrix<Type>& m)
{
assert(m.cSize == cSize && m.rSize == rSize);
int i, j;
for (i = 0; i < cSize; ++i)
for (j = 0; j < rSize; ++j)
p[i][j] = m.p[i][j];
return (*this); // returns the actual total object.
}

template<class Type>
Matrix<Type>& Matrix<Type>::operator+=(Matrix<Type>& m)
{
assert(m.cSize == cSize && m.rSize == rSize);
int i, j;
for (i = 0; i < cSize; ++i)
for (j = 0; j < rSize; ++j)
p[i][j] += m.p[i][j];
return (*this); // returns the actual total object.
}
template<class Type>
Matrix<Type>& Matrix<Type>::operator*=(Matrix<Type>& m)
{
assert(m.cSize == cSize && m.rSize == rSize);
int i, j;
for (i = 0; i < cSize; ++i)
for (j = 0; j < rSize; ++j)
p[i][j] *= m.p[i][j];
return (*this); // returns the actual total object.
}
*/
_________________
Kjell Gunnar Bleivik
Make it simple, as simple as possible but no simpler: | DigitalPunkt.no |
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    ForumNorway.com Forum Index -> C++ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum