473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Which option is better to use

I have a private vector list in a class and I want to have a function that returns the vector. I could either say

vector<int> getvectorlist()
{
return vectorlist;
}

or
vector<int> *getvectorlist()
{
return &vectorlist;
}

or

vector<int> &getvectorlist()
{
return vectorlist;
}

or just return the value with in the list

int getdata( int Num )
{
vect iter = vectorlist.begin()+Num;
return (*vect );
}

where in main there would be a for loop calling that function.

so which option is the best choice.

Oh and im just wanting to know what data there is, not wanting to modify the list at all
Mar 28 '08 #1
3 1092
gpraghuram
1,275 Expert 1GB
My idea would be a class which contains the vector.
Create a object instance and then using the object call the method which creates the vectorlist(That is update the member of the class).

Then use the object to know the details of the vector


Raghuram
Mar 28 '08 #2
fual
28
I have a private vector list in a class and I want to have a function that returns the vector. I could either say

vector<int> getvectorlist()
{
return vectorlist;
}

or
vector<int> *getvectorlist()
{
return &vectorlist;
}

or

vector<int> &getvectorlist()
{
return vectorlist;
}

or just return the value with in the list

int getdata( int Num )
{
vect iter = vectorlist.begin()+Num;
return (*vect );
}
[/
where in main there would be a for loop calling that function.

so which option is the best choice.

Oh and im just wanting to know what data there is, not wanting to modify the list at all
It all depends what you intend to do with this list, but if you just want to access the data without modifying it then the best thing might be:
Expand|Select|Wrap|Line Numbers
  1. const vector<int>& get_vector_list( void ) const
  2. {  return vectorlist; }
That will prevent it from being modified. Alternatively you might want to provide access only to the "at" function and const_iterator "begin" and "end" functions.
Mar 28 '08 #3
thanks for the reply's
Apr 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
3
by: Unforgiven | last post by:
I have the following situation: Given this class: template<typename T> class Expression { /* omitted */ }; This is the base class for a BooleanExpression and an ArithmeticExpression.
106
by: cfmortgagepro | last post by:
Hi, I know that I'm an extreme newb by asking this overly beaten question, but I am leaning toward C#, becuase the perception is that it is better to learn than VB.Net. I guess it makes you...
53
by: Jon S via DotNetMonster.com | last post by:
Hi all, I'm planning on developing an ASP.NET web site. I know both VB.NET and C# but am unsure on which would be more useful to develop an ASP.NET site with? Also I maybe looking to become a...
16
by: tinman | last post by:
Hi... I have the following two code excerpts. It basically reads data froma dataReader and adds it to a collection.... Excerpt A: ******* With ProjectData
1
by: zorro | last post by:
and does testing merely mean running it 100 000 times and clocking it? // using preg_replace : $s = ' <select name="color"> <option value="">choose <option value="red">red <option...
4
by: John | last post by:
Hi <form nam="country" ... <select name="industy" ... <option ... selected... </option> <option ... Now, in Javascript, I want to change defaulted "selected" to fourth option.
4
by: rebeccatre | last post by:
please help me with this, <style> #a, option.message {background-color: green; color: white;} #b, option.message {background-color: yellow; color: black;} </style> <select id="thisselect">...
3
by: shapper | last post by:
Hello, I need an advice: I have 3 tables: Posts, Events and Files. Each post, event and file can be a associated to one or many tags. My idea was to create only one Tags table. Note that...
3
by: sameaname | last post by:
Hi We have the below 6 class libraries in our ASP.NET project 1. Application.UI - //Contains all the aspx and UI control, css/ images web.config etc. (assembly name : Project.Application.UI)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.