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++?
chris_m_willis
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();
JHorn
Yeah I think this is 'a' solution.
Thanks brian.
Any one with a better solution to this problem is always welcome!
Thanks
Nibu thomas.
Ken England
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
syeager
wintergreen-joe
Yutong MSFT
{
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
JVled
Thanks Andreas.
Kang Su
Ooops.
RMarmion
Have you considered static methods Then you will know that it is your base class that gets the call.
MalamisuraE
Thanks
Nibu thomas.
Squirrel
wonderliza
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
dubdiz
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++.
v0id
But this is for C++ Managed Extensions. I am not using them.
This is pure C++.
Thanks,
Nibu thomas.