Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

how to remove those compiler warnings

(1/4) > >>

ollydbg:

--- Code: ---include\editorbase.h:36:22: warning: 'virtual void EditorBase::operator=(const EditorBase&)' was hidden [-Woverloaded-virtual]
include\cbeditor.h:70:22: warning:   by 'virtual void cbEditor::operator=(const cbEditor&)' [-Woverloaded-virtual]
--- End code ---

I see a lot of such warnings, can we remove them?

Thanks.

MinGW GCC 4.6.3.

oBFusCATed:
There is no point in operator= being virtual. You can try to remove the virtuals and see what happens :)

MortenMacFly:

--- Quote from: oBFusCATed on June 04, 2012, 06:26:48 pm ---There is no point in operator= being virtual. You can try to remove the virtuals and see what happens :)

--- End quote ---
Why not? If you specialise EditorBase you should ensure also to specialise this operator, don't you?

jarod42:

--- Code: ---class DerivedClass : public BaseClass
{
using BaseClass::hiddenFunction;

// other stuff.
};

--- End code ---
should remove the warnings.

but I agree that

--- Code: ---DerivedClass::operator =(const BaseClass&)
--- End code ---
is strange

oBFusCATed:

--- Quote from: MortenMacFly on June 04, 2012, 08:24:05 pm ---Why not? If you specialise EditorBase you should ensure also to specialise this operator, don't you?

--- End quote ---
It is quite more complex.
Here is a thorough explanation: http://icu-project.org/docs/papers/cpp_report/the_assignment_operator_revisited.html (scroll to the virtual assignment).


--- Quote ---Remember clone()? This is the polymorphic copy constructor. If you need polymorphic copy on a group of related classes, you define a virtual function called clone() and every class in the tree overrides it to call his own copy constructor. You can’t just call X’s copy constructor for the same reason you can’t just call X’s assignment operator.

--- End quote ---

And this is an explanation for the warning: http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
It happens because the compiler always generates Derived& operator=(Derived &p) no matter if there is Base& operator=(Base &p) (virtual or not).

p.s. I suppose the best we could do is to make operator= an unimplemented private function.

Navigation

[0] Message Index

[#] Next page

Go to full version