The following code illustrates a problem I have run into where it fails to compile with an undefined reference to Def::DEFAULT;
However if I comment out the 2nd line in main it will compile and run fine, I am able to "see" the value assigned to DEFAULT either through a cast to int or assigning to the Val class int data member directly.
template <typename T, T def>
class Def {
public:
static const T DEFAULT = def;
enum {DEFAULT_ENUM = DEFAULT};
};
class Val {
public:
Val& operator=(const int &val_in) {
val = val_in;
return *this;
}
int val;
};
typedef Def<int, 10> Def_t;
Val test_val;
int main()
{
test_val = Def_t::DEFAULT_ENUM; // works
test_val = Def_t::DEFAULT; // fails to compile
test_val = (int) Def_t::DEFAULT; // works
test_val.val = Def_t::DEFAULT; // works
}