-
Junior Member
Dynamic Polymorphism in C
How can we obtain dynamic polymorphism in C? (read my question fully)
how to maintain two different types of records (say student and employee) using linked list (with the concept of queue or stack)...
But the only condition is the function for add and delete (both in queue or stack) should have a same coding for both the records, and the function will act for two different records in base of the arguments... (how can we obtain dynamic polymorphism in C, with passing the structure in dynamic) if any body will to answer plz mail the programme...
-
Junior Member
Re: Dynamic Polymorphism in C
I am a little out of touch with coding. So, I may not the actual code part right. However, in theory, there are a couple different ways to achieve what you are asking. You are asking to write a function that dynamically reacts to its parameter's type. The assumption here is that the records contain comparable data (empID/StudentID, EmpName/StudentName, EmpAddress/StudentAddress etc).
One way of achieving this is by writing a template function. Another way of writing this is having a C union. Create a union of two distinct structures, one for employee data and another for student data. If you can pass the union object as your function parameter, then inside the function, you can check for the type of data being passes and have the function execute accordingly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules