This wild beast of human imagination
delete ship1, ship2;
deletes ship2
, but doesn’t delete ship1
. Comma here is treated as sequence (comma) operator, and result of such expression is result of last sub-expression.
Your function always returns 1. You probably meant something like this
int shipdetcol(spaceship &ship1, spaceship &ship2, float colrange)
{
return colrange > sqrt(abs(((ship1.x - ship2.x)*(ship1.y - ship2.y)));
}
Note you need absolute value of difference between coordinates.
Lastly, it’s C++, so don’t use:
#include <string.h>
#include <math.h>
use
#include <cstring>
#include <cmath>
Don’t use
char callsign[51];
Use
#include <string>
std::string callsign;
Now you can do:
ship1 = new spaceship { 0, 0, "Red1"};