Declare template without parameters
c++, templates
Solution
Templates are resolved at compile time; your template parameters can't depend on values that aren't known until runtime. Furthermore, each instance of a template is a different type: `X<1, 2>` and `X<3, 4>` are different just like two classes `Foo` and `Bar` are different; a variable of the one type can't hold a value of the other. You can't have a variable whose type is just `X`, because `X` is not a type (it's a template).
It doesn't make sense for a template to have no parameters; you don't need a template at all in that case. It's not clear why you're trying to use templates to add two variables. You probably want to just use a class that holds two integers passed to its constructor:
class X {
private:
int i, j;
public:
X(int i, int j): i(i), j(j) { }
int doSomething() const { return i + j; }
};
This will let you have variables of type `X`, and you can construct different instances of `X` with different values for `i` and `j` based on variables at runtime.
Problem
Is it possible to declare a template without parameters? I have a template like: ``` template < int i, int j> class X{ int doSomething() { return i+j;} } ``` and now i want to use this Template in another class, but i don't know its parameter cause they are variable. But i would like to save different templates in a variable like this : ``` class Foo { X var; void setVar ( const X &newVar) { var = newVar; } X getVar () { return var;} } ``` Is there a way to save different types of the template in one variable ? or pointer ? Thx for help