Paul,
I tried this code and it compiles, but crashes. Can you point me in the right direction? Do I need to use the GlobalAlloc stuff for this?
// dVector_test.src
// test program for DVector class
// by John Siino (01/05/2007)
#include "dVector.inc"
sub main(),int
{
DVector A[3];
for x = 0; x < 3; x++
{
A[x].Resize(3);
}
for x = 0; x < 3; x++
{
for int i = 0; i < 3; x++
{
A[x].Set(i, RND(100));
}
}
for x = 0; x < 3; x++
{
A[x].Write("Original Vector A[", "numtostr(x,0)", "] = ", 3 );
writeln("\n\n");
}
print("Angle between Vectors: A[0] and A[1] is ", A[0].AngleD( A[1] ), " degrees\n\n");
writeln("\n\n");
writeln("Press any key to continue\n");
while GetKey() = "";
writeln("\n\n");
return 0;
}
John
Quotefor x = 0; x < 3; x++
{
for int i = 0; i < 3; x++
{
A
I'm not sure but it looks to me like you're incrementing x in 2 places inside one for loop.
Shouldn't "for int i = 0; i < 3; x++" really be "for int i = 0; i < 3; i++"
That inner for loop just looks wrong to me.
Larry
That and arrays of classes won't be properly constructed. Only the first element of the array will be. I've mentioned that before ;)
D'oh!
It was late. Thanks for the feedback Larry & Paul.
Paul what would it take to allow an array of classes? Is that a useful concept?
You could use a list of classes instead. Right now the compiler doesn't directly support arrays of classes, although you can make it work if you manually call the constructor for each element > 0 and then call the destructor for each element > 0 when you are done with the array.
The constructor has the same name as the class, so ...
for x = 1; x < 3; x++
{
A[x].DVector();
}
Would call the constructor for each element of the array, except the first which is called by the compiler and...
for x = 1; x < 3; x++
{
A[x]._DVector();
}
Would call the destructors when you are finished.
Paul.
Yeah... that's right... Paul
That's exactly what i WAS GOING TO TELL HIM TO DO! ;D
Edited my post since the forum was changing the array symbol to a square block ::) That'll teach me to use code blocks ;)
Awesome, I'm going to try it on my Vector Math stuff I'm doing.
BTW, I found some stuff regarding "Multi-dimensional vector product" by Z. K. Silagadze of Budker Institute of Nuclear Physics, Novosibirsk, Russia. I also found material on Wikipedia. I'm going to see if I can apply the information gleaned in my Aurora Vector Math module.
I would also like to know how to use Aurora stuff (via dll or directly coded in) in Ebasic. Does the GlobalAlloc stuff work in the same way in EBasic?
QuoteThat's exactly what i WAS GOING TO TELL HIM TO DO!
You too?
Quote from: Paul Turley on January 05, 2007, 11:49:15 AM
You could use a list of classes instead. ... if you manually call the constructor for each element > 0 and then call the destructor for each element > 0 when you are done with the array.
Should the destructor be called in decreasing order or does it not matter?
for x = 2; x >0; x--
{
A [ x ] . _DVector();
}
Doesn't matter as you are calling the destructor of individual classes, not derived.