I understand that a template type parameter can be defaulted, however, this doesn't work when I attempt to construct a std::vector
without supplying the template argument:
#include<vector>
template <typename Int = int>
struct integer{
Int i;
};
int main(){
integer num;
std::vector<integer> vec;
return 0;
}
This code returns a type value mismatch (compiler explorer link). Is it possible to fix this without writing std::vector<integer<int>>
If you have a function with a default parameter:
int foo(int bar=0);
To call this function you still have to write:
int n=foo();
attempting to write int n=foo;
will not work, of course. For the same reason if your template's parameters are defaulted you still have to use
integer<>
to instantiate the template instead of
integer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With