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++?
Dwight6531
{
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
petedee
kayers
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();
Ramesh Rajagopal
Thanks
Nibu thomas.
Noah Falk - MSFT
Thanks Andreas.
tgroebner
Ooops.
Amy R Hagstrom
Windows Latvian Langpack
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
rollingdonut
Mike Smith-Lonergan
Have you considered static methods Then you will know that it is your base class that gets the call.
emgreenberg
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
Rick_Parker
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++.
d0mufasa
But this is for C++ Managed Extensions. I am not using them.
This is pure C++.
Thanks,
Nibu thomas.
ZAiNT
Yeah I think this is 'a' solution.
Thanks brian.
Any one with a better solution to this problem is always welcome!
Thanks
Nibu thomas.