Re: What's the different betteen pure virtual function and virtual function
In article
<daniel_t-0BA75B.06391803062008@earthlink.vsrv-sjc.supernews.net>,
"Daniel T." <daniel_t@earthlink.net> wrote:
Jack <Jack.L.China@gmail.com> wrote:
I meet a question with it ,
I did not get clear the different betteen them,
First, pure virtual:
class Base1 {
public:
virtual void pure() = 0;
};
class Derived1 { }; // will not compile
class Derived2 {
public:
void pure() { cout << "pure\n"; }
};
int main() {
Base1 b; // will not compile
}
Now virtual:
class Base1 {
public:
virtual void vert();
};
class Derived1 { }; // will compile
int main() {
Base1 b; // will compile
}
That's the difference.
Well, I posted the above without much due diligence! Sorry about that...
class Base {
public:
virtual void pure() = 0; // whether Base1::pure() is defined or not
};
class Derived1 : public /*or protected or private*/ Base1 { };
class Derived2 : public Base1 {
public:
void pure() { }
};
int main() {
Base b; // will not compile
Derived1 d; // will not compile
Derived2 d2; // will compile
}
now virtual:
class Base {
public:
virtual void virt() { }
};
class Derived1 : public /*or protected or private*/ Base1 { };
class Derived2 : public Base1 {
public:
void virt() { }
};
int main() {
Base b; // will compile
Derived1 d; // will compile
Derived2 d2; // will compile
}