Date: Mon, 28 Jun 2021 15:24:35 +0800
Hi,
Recently I met a problem described as the title, here is the background.
I am cleanning some codes with the warning of overloaded virtual functions.
Here is the introduction for overloaded virtual functions:
https://stackoverflow.com/questions/18515183/c-overloaded-virtual-function-warning-by-clang
Simply, for the codes:
```
struct Base
{
virtual void * get(char* e);
// virtual void * get(char* e, int index);
};
struct Derived: public Base {
virtual void * get(char* e, int index);
};
```
Compilers would complains about:
```
warning: 'Derived::get' hides overloaded virtual function [-Woverloaded-virtual]
```
And the corresponding suggestion is:
```
struct Derived: public Base {
using Base::get; // tell the compiler we want both the get from Base and ours
virtual void * get(char* e, int index);
};
```
Then I use this method to refactor our codes and I run into problems with:
```
struct Base {
virtual void * get(char* e);
private:
virtual void * get(char* e, int index);
};
struct Derived: public Base {
using Base::get; // Now the compiler complains that Base::get is private.
virtual void * get();
};
```
At first, I thought it is a compiler bug. Since I think the compiler should search for the accessible part first.
However, I find these words in 9.9.14 N4878,
```
In a using-declarator that does not name a constructor, every declaration named shall be accessible.
```
So the behavior of compiler is consistent with the standard. Then I want to ask,
do you guys think it is a defect in the standard or there is any solution other than
more aggresive refactoring?
BTW, I send this to both std-discussion and std-proposal since I guess it is
related to both. Remind me if anyone isn't comfortable.
Thanks,
Chuanqi
Recently I met a problem described as the title, here is the background.
I am cleanning some codes with the warning of overloaded virtual functions.
Here is the introduction for overloaded virtual functions:
https://stackoverflow.com/questions/18515183/c-overloaded-virtual-function-warning-by-clang
Simply, for the codes:
```
struct Base
{
virtual void * get(char* e);
// virtual void * get(char* e, int index);
};
struct Derived: public Base {
virtual void * get(char* e, int index);
};
```
Compilers would complains about:
```
warning: 'Derived::get' hides overloaded virtual function [-Woverloaded-virtual]
```
And the corresponding suggestion is:
```
struct Derived: public Base {
using Base::get; // tell the compiler we want both the get from Base and ours
virtual void * get(char* e, int index);
};
```
Then I use this method to refactor our codes and I run into problems with:
```
struct Base {
virtual void * get(char* e);
private:
virtual void * get(char* e, int index);
};
struct Derived: public Base {
using Base::get; // Now the compiler complains that Base::get is private.
virtual void * get();
};
```
At first, I thought it is a compiler bug. Since I think the compiler should search for the accessible part first.
However, I find these words in 9.9.14 N4878,
```
In a using-declarator that does not name a constructor, every declaration named shall be accessible.
```
So the behavior of compiler is consistent with the standard. Then I want to ask,
do you guys think it is a defect in the standard or there is any solution other than
more aggresive refactoring?
BTW, I send this to both std-discussion and std-proposal since I guess it is
related to both. Remind me if anyone isn't comfortable.
Thanks,
Chuanqi
Received on 2021-06-28 02:24:41