[Bug c++/42330] undefined reference to "static const int" in class when passing as "const int &" to a function

aijunbai at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Dec 8 14:06:00 GMT 2009



------- Comment #9 from aijunbai at gmail dot com  2009-12-08 14:06 -------
(In reply to comment #8)
> Then show here exactly what you are trying to compile. Note: this is *not*
> gcc-help.
> 

alright, take the flowing code as an example:

template<int>
struct A {
    static const int i = -1;
};

template<>
struct A<0> {
    static const int i = 0;
};

template<>
struct A<1> {
    static const int i = 1;
};

template <int N> const int A<N>::i;

int foo(int)
{
}

int bar(const int &)
{
}

int main()
{
    foo(A<1>::i); //ok here
    bar(A<0>::i); //g++ complains undefined reference to `A<0>::i'

    return 0;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42330



More information about the Gcc-bugs mailing list