Hi, LeafyCircuits here!
Comp Specs:
OS: Windows 7 Home Premium 64-bit
Compiler: MinGW v4.6.2
IDE: Code::Blocks v12.11
edit: ^ Just got MinGW and Code::Blocks
I've recently figured out a function that can erase a specific part of a vector that you specify with a string. It takes in a reference to a vector of char's, and the second arg is what you want to erase, as a string. I got the code working, but now I want to templatize it. However, I've run into this one problem. Take a look at this initialization in my function (don't worry about the rest of the code):
1 2 3 4 5
|
template <typename T>
bool erase_partof(vector<T> &vec, string search)
{
vector<T>::iterator start_itr=vec.begin(), end_itr;
}
|
As you can see, even though I try initializing these iterators, the compiler doesn't recognize that I'm naming a type, since 'T' could be anything. I know that one way of fixing this would be to put 'typename' in front of this declaration, like so:
1 2 3 4 5
|
template <typename T>
bool erase_partof(vector<T> &vec, string search)
{
typename vector<T>::iterator start_itr=vec.begin(), end_itr;
}
|
Although that does indeed work, that method is C++03, and I would rather learn how to use the C++11 method, which uses the 'auto' keyword. However, I'm not sure how to use auto. I have some idea as to how I'm going to use it, but I'm still confused. If anyone would care to explain, that would be wonderful, thanks. :)