Initializing a static constant variable gives me a non-template const template definition

Here is my code:

#include <iostream>
class c{
    public:
    int y;
     c(int x,int p):y(x){
    std::cout<<"has been made"<<std::endl;  
    }


};



template<int x,typename B = void>
struct checkeven{

};


template<typename B>
struct checkeven<0,B>{
    typedef B type;
};



template<int x,int y,class = typename checkeven<x%2,int>::type>
struct t{
    static const c tee;

    static const inline c& initor(){

    return tee;
    }
};

template<int x,int y>
const c t<x,y>::tee(x,y);       //how do i initialize?


int main(int argc, char** argv) {

 //t<2,1>::initor();    
//t<2,2>::initor(); 

    return 0;
}

I tried to study it, but I can not find anything but a suggestion to remove the duplicate by default. I want to implement SFINAE to make sure that the first value is an even number. I have a static constant variable that I want to initialize. It worked perfectly without my default class, but as soon as I added it, everything became messy. How to initialize my constant static member? I would also like to know why my code is not working.

+2
source share
1 answer

You need to specialize your struct template tas follows:

template<int x, int y>
struct t<x,y, typename checkeven<x%2,int>::type> 
{
    static const c tee;

    static const inline c& initor(){

        return tee;
    }
};

, tee :

template<int x, int y>
const c t<x, y>::tee(x, y);

+3

Source: https://habr.com/ru/post/1599628/


All Articles