I want to define default value for my templated container class in the template.
// Example program
#include <iostream>
#include <string>
template <typename T, T TDefault>
class Thing
{
T value;
public:
Thing(T p_value = TDefault):value(p_value) {}
void print()
{
std::cout << value << "\n";
}
};
int main()
{
// This works
Thing<int, 42> thing;
thing.print();
// is there a way to make this work?
Thing<std::string, std::string("Hello, World!")> thing2;
thing2.print();
}
I feel like I'm missing something very obvious ... this should be possible, right?
Basically I just want to make a container class that I can define the default value for when I define it. Instead of having to give a value for it every time I call the constructor.
Yeah I found a neat way around it, I won't post it here because it's not in line with the strict rules of questions and answers of this site.