Next: Resizing a realvec, Up: Realvec
Realvecs may be accessed using var_name(index) = value.
mrs_natural i,j;
realvec foo;
foo.create(10);
for (i=0; i<10; i++) {
foo(i) = i;
}
for (i=0; i<10; i++) {
cout<<foo(i)<<endl;
}
realvec bar;
bar.create(5,10);
for (i=0; i<5; i++) {
for (j=0; j<10; j++) {
bar(i,j) = i+j;
}
}
// pointer for this example
realvec *baz;
// automatically calls calls create
baz = new realvec(10,20);
// we could do it this way if we wanted (instead of the above line)
//baz = new realvec;
//baz->create(10,20);
for (i=0; i<10; i++) {
for (j=0; j<20; j++) {
(*baz)(i,j) = i+j;
}
}
delete baz; // don't forget to free the allocated memory