Quote (Minkomonster @ 17 Jan 2015 23:57)
Typically you make something static when there is a state you want to maintain at the class level, as opposed to at object level. Although, without more information I am not sure what npos is. When you say npos, I think of string::npos. Which is a constant used to indicate the value of a failed search. I have seen it described as the "non-position", "no position", or "null position." Typically when you do a string::find() and a match is not found, the return would be the value set to string::npos, which by default is -1, indicating failure.
In relation to a vector, I am not sure what functions you were overriding. And if you were adding the concept of a npos to this derivation of the vector class, then it would be a static constant, because the value is not meant to change per instance. npos will always be the same regardless of how many instances of vector you instantiate, so its best to just have 1 static copy of it, instead of 1 per object.
oh thx!
itsnt it a problem that if i make it static for the reason just to have only 1 copy of it, that i can only use it in static functions and objects? i only had the knowledge that static = class level object but it wasnt enogh, prof said its bullshit without more info...
I had to override exactly the find, with the stl::search to search a part of my given vector in the already filled one, so i had to use const_iterals too so if i found the stuff i returned with the iteral, if not then with the npos, not like i understood what i am actually doing, i just knew i have to find a normal stl algorithm and use it, in my template class.
This post was edited by Wikings2 on Jan 17 2015 05:58pm