I made some code that dosent work.
I wrote it first for the stack, that means without "new" and "delete" and pointers. And it worked.
The Problem is the Substract-Funktion. I
Its written in Visual Studio 2005, Windows XP.
The Error says:
error C2440: '=': '__w64 int' cannot be converted into 'Point *'
Here is the code:
// Collision_Detection_Suite.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
/////////////////////////////////////////////////////////////////////////
// Point Class ////////////////////////////////
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Point
{
float x,y,z;
public:
Point(void);
~Point(void);
Point(float xPos,float yPos,float zPos);
Tapper is a local variable, and no longer exists once this function returns, the memory it occupied may or may not contain the value(s) expected. Why not create a function to return each coordinate? getCoordX(), getCoordY(), getCoordZ().
Your Subtract function suffers from the same problems, return Point, not a pointer to a Point and make SubstractPoint a constant reference.
1 2 3 4 5 6 7 8 9 10
Point Point::operator - (const Point& SubstractPoint)
{
Point Buffer;
float xBuffer, yBuffer, zBuffer;
xBuffer = x - SubstractPoint.getCoordX();
yBuffer = y - SubstractPoint.getCoordY();
zBuffer = z - SubstractPoint.getCoordZ();
Buffer.setCoord(xBuffer, yBuffer, zBuffer);
return Buffer;
}
1 2 3 4 5
Point *A = new Point;
Point *B = new Point(3,4,5);
Point *C = new Point(3,5,7);
A = C - B; // This is SPARTAAA!! I mean err.. pointer arithmetic?!
I'm scratching my head here with your use of pointers and what you are trying to achieve, dereference them if you want any meaningful result. *A = *C - *B;