Android 需要关于使用const参数重写函数的警告吗

Android 需要关于使用const参数重写函数的警告吗,android,c++,g++,constants,porting,Android,C++,G++,Constants,Porting,如何让GCC通知我重新定义具有不同签名的成员函数 我正在将一个大型项目移植到Android上。 由于M$VC和GCC方言的不同,我为函数参数插入了许多const修饰符。 (即,当您调用func(MyClass(something))时,MyClass&可以使用M$,而GCC需要const MyClass&) 问题是,当您更改BaseClass::func()的签名时,您不会收到关于为DerivedClass::func()使用不同签名的警告 下面是一个小程序,显示正在发生的事情: #includ

如何让GCC通知我重新定义具有不同签名的成员函数

我正在将一个大型项目移植到Android上。 由于M$VC和GCC方言的不同,我为函数参数插入了许多
const
修饰符。 (即,当您调用
func(MyClass(something))
时,
MyClass&
可以使用M$,而GCC需要
const MyClass&

问题是,当您更改
BaseClass::func()
的签名时,您不会收到关于为
DerivedClass::func()
使用不同签名的警告

下面是一个小程序,显示正在发生的事情:

#include <stdio.h>
    class Value {
       int x;
       public:
       Value(int xx):x(xx){}
  };
    class Base {
       public:
       virtual void f(const Value&v) {printf("Base\n");}
  };
    class First: public Base {
       public:
       virtual void f(Value&v) {printf("First\n");}
  };
    class Second: public Base {
       public:
       virtual void f(Value&v) {printf("Second\n");}
  };

    int main() {
         Value v(1);
         First first;
         Second second;
         Base*any;
         any = &first;
         any->f(v);
         any->f(Value(2));
         first.f(v);
    //first.f(Value(3)); // error: no matching function for call to 
         First::f(Value)
}
(gcc对于未使用的参数是正确的,但它与此无关。)

因此:
如何让GCC通知我重新定义具有不同签名的成员函数?

应该是-Woverloaded virtual

-Woverloaded虚拟机

 Warn when a derived class function declaration may be an error in
 defining a virtual function (C++ only).  In a derived class, the
 definitions of virtual functions must match the type signature of a
 virtual function declared in the base class.  With this option, the
 compiler warns when you define a function with the same name as a
 virtual function, but with a type signature that does not match any
 declarations from the base class.

这应该是虚拟的

-Woverloaded虚拟机

 Warn when a derived class function declaration may be an error in
 defining a virtual function (C++ only).  In a derived class, the
 definitions of virtual functions must match the type signature of a
 virtual function declared in the base class.  With this option, the
 compiler warns when you define a function with the same name as a
 virtual function, but with a type signature that does not match any
 declarations from the base class.

这比什么都不做要好得多,但也不是一个完美的解决方案。我收到了很多消息,比如
void func(SomeType&)被SomeType func()隐藏了
,而我真正感兴趣的只是那些在
const
修饰符方面不同的消息。@18446744073709551615那么我就无能为力了。这些都是值得关注的事情。为什么你会得到那么多隐藏的函数-蹩脚的命名约定?因为代码是几十年前写的,不是我写的。有些文件可以追溯到1994年。这比没有要好得多,但也不是一个完美的解决方案。我收到了很多消息,比如
void func(SomeType&)被SomeType func()隐藏了
,而我真正感兴趣的只是那些在
const
修饰符方面不同的消息。@18446744073709551615那么我就无能为力了。这些都是值得关注的事情。为什么你会得到那么多隐藏的函数-蹩脚的命名约定?因为代码是几十年前写的,不是我写的。有些档案可以追溯到1994年。