help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linker problem with template specialisation


From: tsotsi
Subject: Linker problem with template specialisation
Date: Thu, 29 May 2008 02:46:30 -0700 (PDT)
User-agent: G2/1.0

I have the following code:

enum foo
{
    null_foo,
    foo1,
    foo2
};

template<typename T>
struct data
{
    T val;
    bool set;

    template<typename U>
    data<T>& operator=(const U &that)
    {
        val = that;
        set = true;
        return *this;
    }
};

struct foo_1 { };
struct foo_2 { };

template<typename T> struct map_foo_type { static foo const id =
null_foo; }; // worst match
template<> struct map_foo_type<foo_1> { static foo const id = foo1; };
template<> struct map_foo_type<foo_2> { static foo const id = foo2; };

Using the above code, I want to be able to do the following:

    data<int> mid = map_foo_type<foo1>::id;

When I compile with gcc 3.3.6 I get a linker error - undefined symbol
mep_foo_type<foo1>::id

If I have an intermediate step:

foo id = map_foo_type<foo1>::id
data<int> mid = id;

then it links fine.

Alternately, if I change operator= above to take const U data, rather
than a reference to const U, it also links fine!

What is the problem please?

Thanks
Steve


reply via email to

[Prev in Thread] Current Thread [Next in Thread]