This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Overload resolution and missing warnings


This is not my code, but I got the following interesting piece recently:

class A
	{
public:
	void f(long)
		{
		cout << "A::f(long)" << endl;
		}
	virtual void f(double)
		{
		cout << "A::f(double)" << endl;
		}
	};

class B: public A
	{
public:
	void f(double)
		{
		cout << "B::f(double)" << endl;
		}
	};

int main()
	{
	B b;
	double x;
	b.f(x);
	long i;
	b.f(i);
	}


the guy who wrote this was surprised to get B::f(double) called twice.

What is most surprising, however, is that g++ does not even give an
inkling of something amiss. No warning whatsoever, even with 
-Wall -Woverloaded-virtual -Weffc++
(okay, some warnings with -Weffc++, but they're related to problems with
iostream :-) )



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]