0

From the following code

template<int N>
struct fibo{
    static const int value = fibo<N-1>::value + fibo<N-2>::value;
};

template<>
struct fibo<1>{
    static const int value = 1;
};

template<>
struct fibo<0>{
    static const int value = 1;
};

constexpr int count_which_fibo(int which, int max, int n_1, int n_2){
    return max<n_1 + n_2 ? which : count_which_fibo(which + 1, max, n_1 + n_2,n_1);
}

template<int first, int... args>
struct container_creator{
    typedef typename container_creator<first-1,first, args...>::type type;

};

template<int... args>
struct container_creator<0,args...>{
    typedef container_creator<0,args...> type;

    static auto create(){
        return std::make_tuple(fibo<args>::value...);
    }
 };

int main(void){
    auto var = container_creator<5>::type::create();
}

I get the following linking error: /tmp/ccV91mii.o: In function container_creator<0, 1, 2, 3, 4, 5>::create()': fibo.cpp:(.text._ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv[_ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv]+0x12): undefined reference tofibo<5>::value' fibo.cpp:(.text._ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv[_ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv]+0x18): undefined reference to fibo<4>::value' fibo.cpp:(.text._ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv[_ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv]+0x1d): undefined reference tofibo<3>::value' fibo.cpp:(.text._ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv[_ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv]+0x22): undefined reference to fibo<2>::value' fibo.cpp:(.text._ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv[_ZN17container_creatorILi0EJLi1ELi2ELi3ELi4ELi5EEE6createEv]+0x27): undefined reference tofibo<1>::value' collect2: error: ld returned 1 exit status Can you tell me why? It looks like a static method create is a problem.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
Matimath
  • 31
  • 1

0 Answers0