Access data in a programming template

I am creating a template class with special behavior for two different sizes and general behavior in a general class, as shown 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 data stream for the class below, I expect to access the _data vector, right ?!

template<typename T>
class Dataset<T, 1>
{
public:
    T & operator()(const size_t & index)
    {
        return _data[index];
    }
};

however, I get a compilation error _data could not be resolved. What is the problem?!! Thanks

+4
source share
1 answer

A class template specializes in its own class, not related to the main template. Therefore, it Dataset<T, 1>does not have a member _databecause you did not declare it in the class definition.

, .

+7

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


All Articles