I am creating a template class with specialized behavior for two different sizes, and general behavior in general class as below::
template<typename T, size_t DIM>
class Dataset
{
public:
// all the constructors are defaulted
// all the general behavior implementation
std::vector<T> _data;
};
Given the flow of data for the class below, I am expecting to have access to _data vector, right ?!
template<typename T>
class Dataset<T, 1>
{
public:
T & operator()(const size_t & index)
{
return _data[index];
}
};
however, I get the compilation error of _data couldn't be resolved. What is the problem here ?!! Thanks
A class template specialization is its very own class, unrelated to the primary template. So Dataset<T, 1>
does not have a _data
member because you did not declare one in its class definition.
If you need common features among different specializations of the same template, you can move them to a shared base class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With