Re: Private implementation of public pure virtual
I don't see how this code could have any practical use, but would
consider it a bug in both compilers...? (The only practical use would
be for hiding away parts of an interface, but then you've got design
issues plus the fact that this just doesn't work).
Comments?
The compiler is right, more this code still works....
class A {
public:
void call_b() { b(); }
virtual void a() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
private:
virtual void b() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};
class B : public A {
public:
virtual void b() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
private:
virtual void a() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};
int main() {
A* a = new B();
a->a();
a->call_b();
}
Cause maybe you need to implement a function that you want to accessed
only
from the interface, or you want to implement a private function (the
template method pattern is a pratical example) but the private doesn't
matter anymore.
To me this is perfectly reasonable
struct C : B {
virtual void a() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
virtual void b() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};
I used this coupled with anonymous namespaces to hide implementation
details and keep definitions compact.
Changes between public and private give you flexibilty ^^
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]