Container Dump

The Program I am trying to create is trying to create an object, copy itself into a global vector of the class, destroy itself, while keeping the vector copy safe. Hear is the code in my header, where my errors are being generated.
Could someone tell me what to change.
class Point
{
double a,b,c;
DWORD color;
int ID;
double d;
bool willLast;
void setLife(bool life){willLast=life;}
static int allIDs;
~Point()
{
std::cout<<"Point "<<ID<<" Destroyed";
}
public:
Point(double a,double b, double c, double d);
};
int Point::allIDs = 0;
std::vector<Point> tempHold;
Point::Point(double a,double b, double c ,double d)
{
ID = allIDs;
std::cout<<"Point "<<ID<<" Created";
allIDs++;
willLast = false;
tempHold[ID].a=a;
tempHold[ID].b=b;
tempHold[ID].c=c;
tempHold[ID].d=d;
tempHold[ID].ID=ID;
tempHold[ID].setLife(true);
if(!willLast)
this->~Point();
}
Last edited on
closed account (D80DSL3A)
Just write a normal constructor:
1
2
3
4
5
6
7
8
9
10
11
12
Point::Point(double _a,double _b, double _c ,double _d)
{
ID = allIDs;
std::cout<<"Point "<<ID<<" Created";
allIDs++;
willLast = true;;
a=_a;
b=_b;
c=_c;
d=_d;
// what about color? Add something for this.
}


Then use it in main() to create a Point object for the vector:
tempHold.push_back( Point(1,2,3,4) );
No extra object will be created here, just the one stored in the vector.
Topic archived. No new replies allowed.