Why can't I use templates members in its specialization?

95 Views Asked by At

Here's my code:

#include <iostream>

template <typename T>
struct Foo
{
public:
    T DataMember;
};

template<>
struct Foo<int>
{
public:
    void bar()
    {
        std::cout << DataMember;
    }
};

When I try to compile it, it gives an

error C2065 'DataMember': undeclared identifier

What I want to do is to use templates members in its specialization.

I tried a lot of things and googled the problem for hours, but everything I find is examples that don't use templates members and other questions related to c++ templates, but not the one I need.

0

There are 0 best solutions below