Ah, I didn't see that. This problem is getting a bit ridiculous. Why don't we just make it a circular linked list of pointers to point objects while we're at it? :/
This is still quite standard "traffic rules" homework. Understanding pointers is critical; you can do a lot without them, but when you have to use them you better know them.
Linked list is an another "traffic rule" test.
(C++14 tries hard to deprecate new but that is "operating a car".)
Someone else had a much more elaborate "pointless" pointer excercise recently. Not a thing you would use in production code, but a pretty thought-provoker nevertheless.
You should use better variables for assignment. x and y are fine in the class since it's a point, but you shouldn't assign them to a variable of the same name. Use newX and newY or X and Y, or something else so they're not exactly the same.
In your program you just have to replace int* with Point*.
Ther is a problem tho, when I change the int* to Point* I can't make Point arr[] = {1, 1, 2 ,2 ,5 ,5};
Since Point is a object now, I can't put ints inside?
What do I have to do?
I also changed some other parts.
Now I am unable to print anything since cout doesn't let me print the Point object.
Is there any way to print it with cout or I have to do something else?
Point* doubleArray (Point arg[], int size) {
int rsize= size*2;
static Point* array = new Point[rsize];//New array
for(int i=0; i<size; i++){
array[i]= arg[i];
}//Copy the passed array to new array
for(int i=size; i<rsize; i++){
array[i]=Point(0,0);
}//Add default zeros
return array;//return the new array with
//double the size and defualt zeros
}//EndofdoubleArray
int main (){
//Point arr[6];
Point arr[] = {Point(1,1), Point(2,2), Point(5,5)};
Point *newArr = doubleArray(arr,6);
for(int i=0; i<6; i++){
cout<<newArr[i]; //print the doubleArray
}
delete [] newArr;
system ("PAUSE");
return 0;
}//Endofmain
I do not think that is the problem since this is the output with the print statements.
cTor called with 1 and 1
cTor called with 2 and 2
cTor called with 5 and 5
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Default cTor called
Assignment operator called with 1 and 1
Assignment operator called with 2 and 2
Assignment operator called with 5 and 5
Assignment operator called with 1.00392e+035 and 4.73116e-306
Assignment operator called with 1.89078e-307 and 2.12648e-314
Assignment operator called with 3.68939e-308 and 5.90184e-315
1 1
2 2
5 5
1.00392e+035 4.73116e-306
1.89078e-307 2.12648e-314
3.68939e-308 5.90184e-315
dTor called for 0 and 0
dTor called for 0 and 0
dTor called for 0 and 0
dTor called for 0 and 0
dTor called for 0 and 0
dTor called for 0 and 0
dTor called for 3.68939e-308 and 5.90184e-315
dTor called for 1.89078e-307 and 2.12648e-314
dTor called for 1.00392e+035 and 4.73116e-306
dTor called for 5 and 5
dTor called for 2 and 2
dTor called for 1 and 1
Press any key to continue . . .