Resharper cannot find protected member, although the compiler can Follow
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
Please sign in to leave a comment.
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.
Thanks, I didn't know that.
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