Compiler Warning C4373 about virtual methods

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


The following code will result in C4373 warning message. In MSDN,

http://msdn2.microsoft.com/en-us/library/bb384874.aspx

I do not quite understand the following statement,

1. What means "bind"? Putting function pointer into the vtable of the related class?

2. const is ignored in derived class?

--------------------
This means the compiler must bind a function reference to the method in either the base or derived class.

Versions of the compiler prior to Visual C++ 2008 bind the function to the method in the base class, then issue a warning message. Subsequent versions of the compiler ignore the const or volatile qualifier, bind the function to the method in the derived class, then issue warning C4373. This latter behavior complies with the C++ standard.
--------------------

Code:
class Base {
public:
	virtual int goo (const int input) {return 200;}
};

class Derived : public Base {
public:
		virtual int goo (int input) {return 200;} // change const property of input parameter
};

int main()
{
	Derived d;
	const int a = 1000;
	d.goo (a); // pass const to non-const

	return 0;
}

Compile warning message,

1>d:\visual studio 2008\projects\test_overriding1\test_overriding1\main.cpp(8) : warning C4373: 'Derived::goo': virtual function overrides 'Base::goo', previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers
1> d:\visual studio 2008\projects\test_overriding1\test_overriding1\main.cpp(3) : see declaration of 'Base::goo'


regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top