GaijinPunch
MIS
Special thanks to dlkfjdlkfjdlfkd on recommending the Accelerated C++ book. I'm working on it at work in my free time -- have made it Chapter 3 in a few days, so I guess that's good progress.
Couple of questions though:
In one of the examples in the book, the authors want to check if a vector (called vectorname here) has any entries in it. So, they do this:
typedef vector<double>::size_type vec_sz;
vec_sz size = vectorname.size()
if (size == 0 ) {
cout << error_message << endl;
return 1;
}
Just goofing around, trying to figure out "why" as I go along, I tried the following:
//typedef vector<double>::size_type vec_sz;
//vec_sz size = vectorname.size()
if (vectorname.size() == 0 ) {
cout << error_message << endl;
return 1;
}
And it worked just fine. If vectorname.size() all by its lonesome will tell you how many entries is has... why go through the hassle... other than introducing soemthing new?
One other one:
I'm used to pushing and popping arrays in Perl. It seems that C++ will complain if I want to push something too much. Are vectors essentially what you have to use instead of an array if you don't know how many objects it's going to hold?
Couple of questions though:
In one of the examples in the book, the authors want to check if a vector (called vectorname here) has any entries in it. So, they do this:
typedef vector<double>::size_type vec_sz;
vec_sz size = vectorname.size()
if (size == 0 ) {
cout << error_message << endl;
return 1;
}
Just goofing around, trying to figure out "why" as I go along, I tried the following:
//typedef vector<double>::size_type vec_sz;
//vec_sz size = vectorname.size()
if (vectorname.size() == 0 ) {
cout << error_message << endl;
return 1;
}
And it worked just fine. If vectorname.size() all by its lonesome will tell you how many entries is has... why go through the hassle... other than introducing soemthing new?
One other one:
I'm used to pushing and popping arrays in Perl. It seems that C++ will complain if I want to push something too much. Are vectors essentially what you have to use instead of an array if you don't know how many objects it's going to hold?