Disabling visual C++ virtual function override warning for certain methods -


i enable c4263 (visual c++) warning on our code base, however, warning gives out false positives. disable warning such false positives disappear. tried simplify issue generic code:

class b { public:     virtual void funca();     virtual void funcb(); };   class d : public b {     virtual void funca(int);         virtual void funcb(int); }; 

with code following warnings: void d::funca(int)' : member function not override base class virtual member function void d::funcb(int)' : member function not override base class virtual member function

what trying achieve disable warning funca (or funcb) , let rest of class affected it.

i tried putting

#pragma warning(push)         #pragma warning(disable:4263)  .  .  . #pragma warning(pop)     

around funca not solve problem. if pragmas wrap whole class both of warnings disappear.

any ideas?

this strange error given documentation it:

https://msdn.microsoft.com/en-us/library/ay4h0tc9.aspx?f=255&mspperror=-2147217396

'function' : member function not override base class virtual member function

a class function definition has same name virtual function in base class not same number or type of arguments. hides virtual function in base class.

the last sentence interesting one, , suggested me if unhide base class functions, warning no longer appear.

and indeed case. following code not output c4263:

class b { public:     virtual void funca();     virtual void funcb(); };  class d : public b {     using b::funca;     using b::funcb;     virtual void funca(int);         virtual void funcb(int); }; 

the warning seems little strange. if you're dispatching base class pointer, doesn't matter functions derived class hides, won't hidden when using base class pointer. herein lies answer!

what's happening here compiler guessing intentions. because introducing new signature, means using either polymorphic or non-polymorphic dispatch using derived pointer (not base pointer). if not doing this, impossible call overload. compiler figures if doing this, hiding un-overridden functions. , that's warning about.

in example:

struct base {     virtual void dothing(int)     {         std::cout << "int  " << std::endl;     } };  struct derived: public base {     virtual void dothing(char) // add function handle chars     {         std::cout << "char  " << std::endl;     } };  int main() {     derived *derived = new derived;     base *base = derived;      base->dothing(1);     derived->dothing(1);     derived->dothing('a'); } 

this outputs:

int char char

the intention may have been add overload handle different case, instead it's hiding existing overloads. warning correct given rules of language. warning isn't exact, it's trivial determine cases doesn't invoked should. in-fact opposite of false-warnings :)

to defeat warning, using declaration should used.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -