Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Polymorphism ..Anyone??

Status
Not open for further replies.

madhosh

Programmer
Aug 10, 2001
14
Where can I find good material on how polymorphism is internally implemented in C++. ?
Thanks
 
I think you can just look into disassembler code. If you want, I posted a code on OOP in C in C forum thread205-115970. Almost the same way is in C++ but is hidden. If you have some more questions, please ask, because I posted a very short sample. It can be made much more labile with some small adds, but in this case it will be much hard to understand. John Fill
1c.bmp


ivfmd@mail.md
 
yes, in C++ is much more simple. All theese details are hidden. John Fill
1c.bmp


ivfmd@mail.md
 
hai everybody,

I feel polymarphism is used for very good user interaction. Simply what is polymarphism ? Object behaves differently in different situation based on the given input parameter.

Suppose if ur creating a userdefined class u for example a calculator class u have to write methods for adding two integers and another method which accepts two flotes like different combinations. Insted of giving different method names u are giving same name so that the end user need not remember different methods. a single method will satisfy all his needs by accepting different type of input paramethers. If u want program send me mail i will sent to u thru mail

Bye
 
#include<iostream.h>
class computer
{
public:
virtual void start() = 0;//means pure virtual function
};//because of pure virtual the class is abstract and can't
//be instanciated directly
class pc:public computer
{
public:
virtual void start()
{cout<<&quot;start_the_pc();&quot;<<endl;}
};
calss makintosh
{
public:
virtual void start()
{cout<<&quot;start_the_makintosh();&quot;<<endl;}
};
void start_computer(computer* cmp)
{
cmp->start();
}
//using computer
int main()
{
computer* xx;
xx = new pc;
start_computer(xx);
delete xx;
xx = new makintosh;
start_computer(xx);
delete xx;
xx = GetCompInterfaceFromOtherPlace
(&quot;for example some CORBA interface if exists such one&quot;);
start_computer(xx);
delete xx;
}
//as you see the interface is declared as computer, but it can be not implemented always in your program. It is a only a interface to a memory location where you don't know anything about it. John Fill
1c.bmp


ivfmd@mail.md
 
All,

When C++ was first developed, it was in the form of a code generator which converted C++ code into C code. The user would then compile the generated C code using their normal C compiler. This program was developed by AT&T and was called cfront (I think).

If you could find this program, and generate a C file from a C++ file, then you can see exactly how the language implements polymorphism, inheritence, classes, etc!!

Of course, modern compilers do a direct compile, so this is currently not available.

Brudnakm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top