V
Victor Bazarov
Interesting article. However, it starts with an example which I find
rather misleading. I hope the author (Christopher Diggins) wouldn't
mind if I post a quote from the article. I know he probably reads or
even writes to c.l.c++.m sometimes.
Christopher gives this [pseudo-]code (yes, it's not C++):
interface IFuBar {
contract:
void FuBar();
};
struct BaseFuBar {
void FuBar() { std::cout << "BaseFuBar"; }
};
struct DerivedFuBar : public BaseFuBar {
void FuBar() { std::cout << "DerivedFuBar"; }
};
main() {
DerivedFuBar d;
BaseFuBar& b = d;
IFuBar i = b;
i.FuBar(); // outputs BaseFuBar
}
and then claims that "the common way to approximate this design
in standard C++ is:"
struct AbcFuBar {
virtual void FuBar() = 0;
};
// vb: missing #include <iostream>
struct BaseFuBar : public AbcFuBar { // vb: public is unnecessary
void FuBar() { std::cout << "BaseFuBar"; }
};
struct DerivedFuBar : public BaseFuBar {
void FuBar() { std::cout << "DerivedFuBar"; }
};
main() { // vb: where is 'int'?
DerivedFuBar d;
BaseFuBar& b = d; /// ************************
AbcFuBar& a = b;
a.FuBar(); // output DerivedFuBar
}
Well, simple superfluosity of 'public', the missing <iostream>, and the
absense of 'main' return value type aside, the code seems logical, yes?
I submit that by changing a single character on the line marked with
asterisks, the desired behaviour can be _correctly_ implemented:
BaseFuBar b = d;
contrary to what the author implies.
Now, I am thinking: should I really read the rest of the article after
seeing that and
main() {
...
in a supposedly _standard_ C++ program?
Christopher is a developer of Heron, another language. I am wondering,
do we really need another language developed because somebody hasn't got
around to learning existing ones well enough? Nah, that can't be it...
Anyway...
Victor
rather misleading. I hope the author (Christopher Diggins) wouldn't
mind if I post a quote from the article. I know he probably reads or
even writes to c.l.c++.m sometimes.
Christopher gives this [pseudo-]code (yes, it's not C++):
interface IFuBar {
contract:
void FuBar();
};
struct BaseFuBar {
void FuBar() { std::cout << "BaseFuBar"; }
};
struct DerivedFuBar : public BaseFuBar {
void FuBar() { std::cout << "DerivedFuBar"; }
};
main() {
DerivedFuBar d;
BaseFuBar& b = d;
IFuBar i = b;
i.FuBar(); // outputs BaseFuBar
}
and then claims that "the common way to approximate this design
in standard C++ is:"
struct AbcFuBar {
virtual void FuBar() = 0;
};
// vb: missing #include <iostream>
struct BaseFuBar : public AbcFuBar { // vb: public is unnecessary
void FuBar() { std::cout << "BaseFuBar"; }
};
struct DerivedFuBar : public BaseFuBar {
void FuBar() { std::cout << "DerivedFuBar"; }
};
main() { // vb: where is 'int'?
DerivedFuBar d;
BaseFuBar& b = d; /// ************************
AbcFuBar& a = b;
a.FuBar(); // output DerivedFuBar
}
Well, simple superfluosity of 'public', the missing <iostream>, and the
absense of 'main' return value type aside, the code seems logical, yes?
I submit that by changing a single character on the line marked with
asterisks, the desired behaviour can be _correctly_ implemented:
BaseFuBar b = d;
contrary to what the author implies.
Now, I am thinking: should I really read the rest of the article after
seeing that and
main() {
...
in a supposedly _standard_ C++ program?
Christopher is a developer of Heron, another language. I am wondering,
do we really need another language developed because somebody hasn't got
around to learning existing ones well enough? Nah, that can't be it...
Anyway...
Victor