Hi guys,
My problem is this.
class Base
{
public:
void OneFunction()
{
cout<<"Base";
}
};
class Derived:public Base
{
public:
//overriden, I don't want this to happen.
void OneFunction()
{
cout<<"Base class function gone";
}
};
Now base class implementation of OneFunction is gone. The derived class has overriden (even though not really) the function. Whenever derived calls OneFunction it will be calling it's own implementation. I want to stop this from happening.
Is it possible
I am actually writing classes which are meant to be distributed. Problems are occurring due to the above mentioned reasons.
Help Needed.
Thanks,
Nibu thomas.

Is there any thing equivalent to NotOverridable in C++?
qrli
There's always the "don't do that" answer. Don't create B::OneFunction() if you don't want to hide A::OneFunction(). If you're worried about accidental hiding, then name the base method differently.
Brian
HMSDME
Thanks
Nibu thomas.
sergiotarrillo
Have you considered static methods Then you will know that it is your base class that gets the call.
highlander777
Turbosolo
Thanks Andreas.
scorpionguy
Saeedsad
Oops - that won't work - you're not using C++ 2005 either...
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up VB.NET code
pavway
But this is for C++ Managed Extensions. I am not using them.
This is pure C++.
Thanks,
Nibu thomas.
Russ Perna
Ooops.
-Mak-
{
public:
void OneFunction() sealed
{
cout<<"Base";
}
};
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up VB.NET code
reelbigfish37
GalogenOleg
class Base
{
public:
void OneFunction()
{
cout<<"Base";
}
};
class Derived:public Base
{
public:
//overriden, I don't want this to happen.
void OneFunction()
{
cout<<"Base class function gone";
}
void CallOneFunction()
{
// Calls OneFunction() in base class instead of overriden
Base::OneFunction();
}
};
With a static function you can never override it.
class Base
{
public:
statiuc void OneFunction()
{
cout<<"Base";
}
};
//Always called like this
Base::OneFunction();
RogerV
Yeah I think this is 'a' solution.
Thanks brian.
Any one with a better solution to this problem is always welcome!
Thanks
Nibu thomas.
dickj
So again this is no solution. You can always override a function in a base class, there is no trick to prohibit this in standard C++.