Resharper cannot find protected member, although the compiler can

I get errors from Resharper if a templated sub-class tries to access a protected field in the base class.

In this example

template <typename T>
class Base
{
protected:
   T _x = 0.0;
};

template <typename T>
class Sub : public Base<T>
{
T fn()
{
   return _x; // This is where squiggles appear
}
};

the final _x is squiggly and it says "cannot resolve symbol _x".

If I turn Resharper code analysis off, it is goes away and it compiles either way.

Is there a reason for this, or an option that will disable the squiggles?

 

I am using VS 2017 15.8.4 with Intel C++19

3 comments
Comment actions Permalink

Hello,

According to the C++ standard you cannot directly access a member from a dependent base, you need to qualify it in some way. See https://gcc.godbolt.org/z/zIQGMi for examples on how to make this code correct.

0
Comment actions Permalink

Thanks, I didn't know that.

0
Comment actions Permalink

Just for the sake of completeness: You only need to qualify the access if the base class is a template class and you do not define the template parameter. 
https://stackoverflow.com/questions/4643074/why-do-i-have-to-access-template-base-class-members-through-the-this-pointer

0

Please sign in to leave a comment.