1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
//mesh.h
#ifndef MESH_H_
#define MESH_H_
#include <iostream>
#include <vector>
#include "Point.h"
#include "Square.h"
class Mesh
{
private:
int lenght,width; // not sure why you had 'noSq' and 'noSquares'
std::vector<Square> squares; // just use a vector to keep track of your squares
// do not dynamically allocate them.
std::vector<Point> points; // ditto for points
public:
Mesh()
{
lenght=width=0;
// noPts=4; // instead of doing this...
// points = new Point[noPts];
points.resize(4); // just do this
// noSq=1; // and instead of this
// squares = new Square[noSq];
squares.resize(1); // just do this
// this works the same as before
points[0]=*(squares[0].tellP1());
points[1]=*(squares[0].tellP2());
points[2]=*(squares[0].tellP3());
points[3]=*(squares[0].tellP4());
}
Mesh(int l, int w)
{
// noPts=4; again... ditch this crap
// points = new Point[noPts];
// noSq=1;
// squares = new Square[noSq];
points.resize(4);
squares.resize(1);
lenght=l;
width=w;
/* this can be shortened
Point p1(0,l,0);
Point p2(0,0,0);
Point p3(w,0,0);
Point p4(w,l,0);
points[0]=p1;
points[1]=p2;
points[2]=p3;
points[3]=p4;
*/
points[0] = Point(0,l,0); // although it would be better to call a
points[1] = Point(0,0,0); // "set" style function if there's one available
points[2] = Point(w,0,0);
points[3] = Point(w,l,0);
// this also works the same... but I'm weary on your use of pointers here....
Square waa(points,(points+1),(points+2),(points+3));
squares[0]=waa;
squares[0].printSquare();
}
/* Get rid of this entirely. vector cleans up automatically. If you don't 'new'
then there's nothing to delete
~Mesh()
{
delete &lenght;
delete &width;
delete &noSquares;
delete[] squares;
delete[] points;
squares=0;
points=0;
}*/
};
#endif /* MESH_H_ */
|