I am reading about the std::vector
class from here. and I am a little bit confused about the template parameters used. The declaration used is:
template<
class T
class Allocator = std::allocator<T>
> class vector;
The parameter class Allocator = std::allocator<T>
is confusing me.
Is this is an example of template template parameter?
I think, however, it might fit into the type-parameter-key name(optional) = default
, which is Type template parameter
, which I found here.
I tried an experiment with the following, but it gives a compilation error:
the value of d1 is not usable in a constant expression
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
//Type template parameter
template<class T>
class foo{
T a;
public :
void sayHello(){
cout<<"Say Hello to : "<<a<<endl; //Would have taken care of the overloaading << , if there were no other errors
}
void setVal(T temp){
this->a = temp;
}
};
class dog{
string name ="labrador";
};
int main(){
dog d1;
//foo<d1> foo_1; ////Does not work
return 0;
}
How can I make the above code work?