English 中文(简体)
没有为隐藏具有类似原型的非虚拟方法发出警告(G++4.4)。
原标题:No warning for hiding non-virtual methods with similar prototype (G++ 4.4)

在我们的项目中,情况(但确实发生)是,在一个衍生类别中,基级的非虚拟方法被同一原型的方法所掩盖。 在此情况下,汇编者(就我们的情况而言为++4.4)保持平静。 虽然我可以看到,对私人方法而言,任何警告都不会有用,但对于受保护或公用方法而言,这至少应该是一种可预示的警告。

如果存在这种情况,我无法找到。

在这里,我要举一个小小小的例子来抱怨(可以保证,这种手法永远不会像在一枪中写的,通常在某个时候工作是A的虚拟方法,后来发生不可复制的变化):

class A
{
public:
    void work(int p)
    { /* do something */ }
};

class B : public A
{
public:
    void work(int p) 
    { /* do something different */ }
};

Result: no warning even with -Wall -Wextra.

问题回答

你不要凌驾于这一方法之上,你再次躲藏起来。 它具有C++特征。

http://www.paragia.com/c++-faq-lite/strange-inheritance.html#faq-23.9”rel=“nofollow” 。

另外,一份有趣的摘录:

Note: warnings are not part of the standard, so your compiler may or may not give the above warning.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签