Hi !
When I compile this piece of code I get the following error:
"NewShapes.cpp: In function `int main()':
NewShapes.cpp:12: error: `ShapePtr' cannot appear in a constant-expression
NewShapes.cpp:12: error: template argument 1 is invalid
NewShapes.cpp:12: error: template argument 2 is invalid"
If necesary, I may change all code but not the code in main (sorry). I may add code to the main but not change it.
Here is NewShapes.cpp (main):
Code:
#include <vector>
#include <fstream>
#include <string>
#include "Vertex.h"
#include "Shape.cpp"
#include "Listan.h"
using namespace std;
main() {
cout << endl;
Listan ShapePtr;
vector<ShapePtr> shapevec;
Vertex varr[] = { Vertex(0,0), Vertex(10,0), Vertex(5,2), Vertex(5,5) };
shapevec.push_back( shapePtr(new Polygon(1, 4, varr, 4)) );
shapevec.push_back( shapePtr(new Circle(5, 5, 4)) );
shapevec.push_back( shapePtr(new Rectangle(4, 10, 2, 4)) );
shapevec.push_back( shapePtr(new Point(6, 7, 1)) );
ofstream is("fil.dat");
ostream_iterator<const shapePtr> shapeout(os, "\n");
copy( shapevec.begin(), sahpevec.end(), shapeout);
os.close();
ifstream is("fil.dat");
for (list<shapePtr>::iterator it = shapelist.begin(); it != shapelist.end(); it++)
cout << *it << endl;
shapevec.insert( shapevec.end(), shapelist.begin(), shapelist.end() );
shapevec.erase(remove_if( shapevec.begin(), shapelist.end(), CloseTo( Vertex(6, 7)) ), shapevec.end() );
ostream_iterator<const shapePtr>sahpeout(cout, "\n");
cout << sahpevec.size() << endl;
cerr << shapePtr::numshapes << endl;
copy( shapevec.begin(), shapevec.end(), shapecout );
cout << endl;
return 0;
}
I attached the completed code.
Thank You for hint and help.
Adalte.