I have a strange gcc 4.7 problem with c++11 enabled :
When I want to compile this:
constexpr unsigned int getDim(const int e){
return (e==1)? A::Set::Dimension :
(
(e==2)? B::Set::Dimension :
(
(e==3)? C::Set::Dimension :
(
+D::Set::Dimension
)
)
);
}
where for each struct A,B,C,D
a typedef for Set
is defined where the related Set has an int Dimension
, for example
struct SetOne{
static const int Dimension = 1;
}
struct A{
typedef SetOne Set;
}
If I don't use the unary +
infront of D::Set::Dimension
the linker fails complaining about undefined references to SetOne::Dimension.
Is this the same problem as: Undefined reference to static class member
I cannot give a MWE as the problem vanished for a simple example with one .cpp file. ? (but all definitions are for A,B,C,D are in one header file)
Does anybody have a clue what might go wrong here? This is unintuitiv :-)
Observation 2:
If one replaces: +D::Set::Dimension
with 0, it compiles fine, but why the hack the other statements as A::Set::Dimension
do not rise the same linking error?