IonicWind Software

Aurora Compiler => General Discussion => Topic started by: John S on January 05, 2007, 02:48:13 AM

Title: can I make an array of my vector objects?
Post by: John S on January 05, 2007, 02:48:13 AM
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;
}

Title: Re: can I make an array of my vector objects?
Post by: LarryMc on January 05, 2007, 06:36:22 AM
John
Quotefor x = 0; x < 3; x++
     {
         for int i = 0; i < 3; x++
           {
             A
  • .Set(i, RND(100));
                }
          }

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
Title: Re: can I make an array of my vector objects?
Post by: Ionic Wind Support Team on January 05, 2007, 07:31:09 AM
That and arrays of classes won't be properly constructed.  Only the first element of the array will be.  I've mentioned that before ;)

Title: Re: can I make an array of my vector objects?
Post by: John S on January 05, 2007, 11:37:27 AM
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?
Title: Re: can I make an array of my vector objects?
Post by: Ionic Wind Support Team on January 05, 2007, 11:49:15 AM
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.
Title: Re: can I make an array of my vector objects?
Post by: LarryMc on January 05, 2007, 01:30:44 PM
Yeah... that's right... Paul
That's exactly what i WAS GOING TO TELL HIM TO DO! ;D
Title: Re: can I make an array of my vector objects?
Post by: Ionic Wind Support Team on January 05, 2007, 01:48:31 PM
Edited my post since the forum was changing the array symbol to a square block  ::)  That'll teach me to use code blocks ;)
Title: Re: can I make an array of my vector objects?
Post by: John S on January 05, 2007, 03:34:15 PM
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?
Title: Re: can I make an array of my vector objects?
Post by: mrainey on January 05, 2007, 04:16:28 PM
QuoteThat's exactly what i WAS GOING TO TELL HIM TO DO!


You too?
Title: Re: can I make an array of my vector objects?
Post by: John S on January 05, 2007, 06:02:47 PM
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();
}
Title: Re: can I make an array of my vector objects?
Post by: Ionic Wind Support Team on January 05, 2007, 06:34:23 PM
Doesn't matter as you are calling the destructor of individual classes, not derived.