class Base
{
public:
void get (int a)
{
cout<<" inside base "<<endl;
}
};
class Der: public Base
{
public:
void get (char a)
{
cout<<" inside derived "<<endl;
}
};
int main ()
{
Der d;
d.get(10); // derived is getting called
int a =10;
d.get(a); // derived is getting called
}
What happen to the base class funtion get(int)????
Well. Understand u r question. For derived class, both the functions (get(int), get(char)) available and why it is not resolving using function overloading concept.
The a rule, Function overloading will not work across base and derived classes as expected.
The reason is, compiler decides to call a specific function based on pointer instead of what object pointer(Which we expect to happen).
You can get expected results by putting both the functions either in base or in derived classes.
Mixing both overring and oberloading is a bit tricky in C++.
WTF would you like to have two methods in base and derived that differ with signature but have the same name? IMHO this should not compile (but compiles for the language standard designers haven't thought it well enough). Even Object Pascal got it right, with their "override" keyword.
IMHO this should not compile (but compiles for the language standard designers haven't thought it well enough). Even Object Pascal got it right, with their "override" keyword.
It's evident that you don't know C++, the syntax to override a method is different.
Please shut up.
If you think you can do better, join the C++ standards working group
WTF would you like to have two methods in base and derived that differ with signature but have the same name?
Usually this would suggests a mistake, however, it can be used as a means of hiding a base class member function if the designer of the derived class decides that calling the original member function is undesirable or even dangerous.
It's evident that you don't know C++, the syntax to override a method is different.
C++ does not have a distinct syntax for overriding a method. You cannot guess from the declaration of the method alone, if it overrides something or not. It is evident you do not know what "syntax" means.
And of course I could do better. I would just add an explicit override keyword as there was in Object Pascal (many years before C++ was standardized). But C++ is designed by committee. Everyone knows that design-by-committee is the worst kind of design process. Probably anyone from the EFPL group from Lousanne could do better. There is a huge difference between "tinkering" used by the C++ committee and proper language research.
BTW: After several years of working on C++0x the committee found out that the generic concepts proposal is a disaster and won't be included. At least this time - correct decision, but eihter C++ is extremely overcomplicated or the committee is not able to design. Microsoft adds new features to C# like crazy every year or two and they have no problems with inconsistencies or complexity.
Usually this would suggests a mistake, however, it can be used as a means of hiding a base class member function if the designer of the derived class decides that calling the original member function is undesirable or even dangerous.
A feature that is useful in 1% of cases and is problematic in 99% of cases should be dropped from the language completely, regardless of how loud scream the programmers that need that 1%. Failing to do so is one of the causes C++ is a mess. Simply BS had not enough courage to say "no" sufficient number of times.
It is evident you do not know what "syntax" means.
The syntax of a programming language describes the proper form of its programs ( from Compilers: Principles, Techniques, and Tools )
Even if the syntax of C++ to override a method cannot be described by a context-free grammar is still well defined and clear
And of course I could do better.
OK then, I've read somewhere that you need to pay 50 US$ to be present at the C++ committee meetings and that at the third one you can vote. If you are so smart you should go there. http://www.open-std.org/jtc1/sc22/wg21/
The ISO C++ standardization is a fairly massive effort, not a small coherent group of people working to create a perfect language for "people just like themselves." The standard is what this group of volunteers can agree on as being the best they can produce that all can live with.