How to use vector class

Anything that doesn't fit elsewhere.
Post Reply
apoorva bedekar
Posts: 11
Joined: Wed Jan 26, 2011 11:57 pm

How to use vector class

Post by apoorva bedekar »

[quote][I want to create an array of flags using the vector function. I created a vector called flag.

objref flag // this statement is written inside the a template but outside proc init()
public flag // this statement is written inside the a template but outside proc init()
flag = new Vector(22,0) // (22 flags and initializing them to zero), this is written inside proc init()
Now if I set the flag to 1 by using flag.set(0,1)
and then later check if this condition is true by

if( flag.get(0) == 1){

statement to be executed if condition is true.}

I am getting a syntax error in flag.get(0) ==1 statement. How do I rectify the syntax. Also in the documentation I read that flag.x supercedes flag.get(i) and flag.set(i,j) function as it can do both the functions. Also I wanted to know what is x. do I have to declare and initialize it .
Also declaring a vector public is allowed inside a template.

What does vsrcdest mean in x= vsrcdest.fill(value)/quote]
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: How to use vector class

Post by ted »

Nobody uses the Vector class's set() or get() methods anymore. Use the vecname.x[index] notation instead.
I am getting a syntax error in flag.get(0) ==1 statement.
I don't. To discover why you're getting an error message, I'd have to use your code. But rather than trying to debug why you can't get deprecated syntax to work, why don't you just rewrite your code with vecname.x[index] notation? You're going to want to do that anyway, sooner or later.

Code: Select all

what is x.
It is an array, and it is a public member of the Vector class.
do I have to declare and initialize it
You don't have to declare it, because each instance of the Vector class automatically has its own x. You specify its size with the size() method and its contents by individual assignment statements or methods like indgen, fill, etc..
Also declaring a vector public is allowed inside a template.
If this is a question, the answer is yes. It's yes even if this isn't a question.
What does vsrcdest mean in x= vsrcdest.fill(value)
vsrcdest.method(), where method is any method that operates on a Vector and returns a Vector result, means that the method "returns the result in place" i.e. the result overwrites the original Vector. src means "source Vector" and "dest" means "destination Vector".
Post Reply