### Matrix return

Is there a way to make this code more efficient? It works as it is at the moment but do you think it's not the best habbit to return Temp so many times?

 ``123456789101112131415161718192021222324252627`` `````` Matrix Hexagon::GetV2() { Matrix Temp(Vertex2); return Temp; } Matrix Hexagon::GetV3() { Matrix Temp(Vertex3); return Temp; } Matrix Hexagon::GetV4() { Matrix Temp(Vertex4); return Temp; } } Matrix Hexagon::GetV6() { Matrix Temp(Vertex6); return Temp; }``````
Last edited on
I do not know what is Vertex1 - Vertex6 and what is Temp, but it seems that it would be better to write one function with a parameter

Matrix Hexagon::GetV( enum VERTEX );
You can use switch case rather than writing so many function....
What I need to do is actually get all the vertex points of the hexagon so I don't think I can use switch case as this isn't in the 'main' of my program. This is part of my header for the code. I'm thinking that I've written more lines than necessary but not sure how to shorten it. thanks

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` ``````class Hexagon: public Shapes { friend ostream & operator<<(ostream &ConsoleOut, Hexagon &PointHexagon); private: double x; Matrix Vertex1,Vertex2,Vertex3,Vertex4,Vertex5,Vertex6; public: double xi; Matrix Va,Vb,Vc,Vd,Ve,Vf; Hexagon(){x = 0;} Hexagon(double xi) { x = xi; Matrix Va(2,1); Matrix Vb(2,1); Matrix Vc(2,1); Matrix Vd(2,1); Matrix Ve(2,1); Matrix Vf(2,1); Va.SetMatrixData(1,1,0); Va.SetMatrixData(2,1,0); Vb.SetMatrixData(1,1,x); Vb.SetMatrixData(2,1,0); Vc.SetMatrixData(1,1,1.5*x); Vc.SetMatrixData(2,1,x*0.5*sqrt(3.0)); Vd.SetMatrixData(1,1,x); Vd.SetMatrixData(2,1,x*sqrt(3.0)); Ve.SetMatrixData(1,1,0); Ve.SetMatrixData(2,1,x*sqrt(3.0)); Vf.SetMatrixData(1,1,-x*0.5); Vf.SetMatrixData(2,1,x*sqrt(3.0)*0.5); Vertex1.SetRowsColumns(2,1); Vertex2.SetRowsColumns(2,1); Vertex3.SetRowsColumns(2,1); Vertex4.SetRowsColumns(2,1); Vertex5.SetRowsColumns(2,1); Vertex6.SetRowsColumns(2,1); Vertex1 = Va; Vertex2 = Vb; Vertex3 = Vc; Vertex4 = Vd; Vertex5 = Ve; Vertex6 = Vf; } ~Hexagon(){cout<<"Destroying Hexagon"<
Topic archived. No new replies allowed.