-
Well...
I sorta figured something out...
typedef struct clsPoint{
int X, Y;
} Point;
Point createPoint(int a, int b){
Point p;
p.X = a;
p.Y = b;
return (p);
}
Point pn = createPoint(10,15);
I need to know 2 other things now though...
1. Is there a more efficient way to do what I did above?
2. How to make a function that I can use like this:
pn.Move(2, 5); // Moves the point over 2 and down 5.
Could you help me one more time please. Sorry I ask so many questions.
-
1. Instead of:
Point ThisPoint = createPoint( 1, 1 );
you do:
Point ThisPoint = { 1, 1 };
// That *should* work. If not:
Point ThisPoint;
ThisPoint.X = 1;
ThisPoint.Y = 1;
// That is far more 'efficent'
2. You can't, that's a class. The closest you can do is:
void MovePoint( Point * pPoint, int MoveX, int MoveY )
{
if( pPoint != NULL )
{
pPoint->X += MoveX;
pPoint->Y += MoveY;
}
}
// Usage
Point ThisPoint = { 1, 1 };
MovePoint( &ThisPoint, 10, 15 );
3. For god's sake, just use classes.
-
OK... thank you.
1 & 2:
Well... I thought that might be what I would have to do... I just wanted to know if there were better ways to do this in 'c'
3. You can't in 'c' but, I would much prefer that.
:cool: OK Well THANK YOU for your help! :D
-
Why are you using C over C++ anyway?
-
Just as a point of interest, I think it's always a good idea to relearn how to do things without the programming language's help. This is a relatively poor example, but there are places where you would rather use structs than classes and C over C++.