We were trying to define a class using a template:
template<typename _VType, size_t _Len>
class Obc<_VType,_Len> {
private:
size_t len = _Len;
public:
Obc();
Obc(_VType *values);
...
};
and, we expected to be able to use it like:
The compiler in use thinks that Obc is a specialization, which it is not, and hence the error is 'X is not a template':
The example below explains it more clearly (see comments):
template <typename VType, size_t Len>
class Obc { //Non-specialized
private:
size_t len = Len;
public:
Obc(){}
Obc(VType *values){}
};
template<typename VType>
class Obc<VType,5> { //Partially specialized for size_t = 5
//... expects non-specialized declaration
private:
size_t len = 5;
public:
Obc(){}
Obc(VType *values){}
};
class X{};
int main() {
// Using new like this... bad style... leak...
auto m = new Obc<X, 5>(); //Instantiates specialization
auto n = new Obc<X, sizeof(X)>(); //Instantiates original
// your code goes here
return 0;
}
BTW, using new to create Obc implies that it is created on the heap, which is (1) not always necessary, and (2), when done, should be de-allocated. In that case it should be wrapped with some kind of smart_ptr, such as unique_ptr or shared_ptr, depending on ownership semantics:
Rather do (in the above example):
...
Obc<X, 5> m{}; //Instantiates specialization
//or
auto ptr = std::make_shared<Obc<X,5>>();
//...Or some other smart pointer type
...