J
junw2000
In the following code:
#include <iostream>
using namespace std;
class V {
public:
int i;
virtual void f() { cout << "V::f()" << endl;}
};
class A : virtual public V { //LINE1
void f() {cout << "A::f()" << endl; }
};
class B : virtual public V { //LINE2
void f() {cout << "B::f()" << endl;}
};
class D : public A, public B {}; //LINE3
int main() {}
Why LINE3 can not compile?
When I remove the "virtual" at LINE1 and LINE2 and get the following
code:
#include <iostream>
using namespace std;
class V {
public:
int i;
virtual void f() { cout << "V::f()" << endl;}
};
class A : public V { //LINE1
void f() {cout << "A::f()" << endl; }
};
class B : public V { //LINE2
void f() {cout << "B::f()" << endl;}
};
class D : public A, public B {}; //LINE3
int main() {}
LINE3 can be compiled. What is the difference between the two cases?
Thank you.
Jack
#include <iostream>
using namespace std;
class V {
public:
int i;
virtual void f() { cout << "V::f()" << endl;}
};
class A : virtual public V { //LINE1
void f() {cout << "A::f()" << endl; }
};
class B : virtual public V { //LINE2
void f() {cout << "B::f()" << endl;}
};
class D : public A, public B {}; //LINE3
int main() {}
Why LINE3 can not compile?
When I remove the "virtual" at LINE1 and LINE2 and get the following
code:
#include <iostream>
using namespace std;
class V {
public:
int i;
virtual void f() { cout << "V::f()" << endl;}
};
class A : public V { //LINE1
void f() {cout << "A::f()" << endl; }
};
class B : public V { //LINE2
void f() {cout << "B::f()" << endl;}
};
class D : public A, public B {}; //LINE3
int main() {}
LINE3 can be compiled. What is the difference between the two cases?
Thank you.
Jack