View Single Post
Mentor
5Feb2009,13:52  
xpi0t0s's Avatar
Generates a couple of warnings in Visual Studio 2005:

warning C4250: 'D' : inherits 'B::B::function1' via dominance
see declaration of 'B::function1'
warning C4250: 'D' : inherits 'C::C::function2' via dominance
see declaration of 'C::function2'

http://msdn.microsoft.com/en-us/libr...ae(VS.80).aspx

The technique may be powerful but it's one of those neat tricks in C++ where you can write perfectly valid code in one place and get an error in another. If you implement B::function2(), then you get an error (not a warning) on the "d.function2();" line.

Code:
class B : virtual public A
{
  public:
  void function1(void)
  {
    cout<<"FUNCTION ONE"<<endl;
  }
  void function2(void)
  {
	  cout<<"B::FUNCTION TWO"<<endl;
  }
};
.\g04e.cpp(56) : error C2385: ambiguous access of 'function2'
could be the 'function2' in base 'B'
or could be the 'function2' in base 'C'
.\g04e.cpp(56) : error C3861: 'function2': identifier not found

and on line 56 we have:

d.function2();

The call to function2() could well be in a file you haven't touched, and if you're using a compiler that doesn't report errors and warnings as comprehensively as VS2005 then you could be in for some serious head scratching.

For example if d.function2() is in some other file, then probably this will result in a linker error.