0

Compile time polymorphysm or runtime

Hi Refer code below: I know it is static / compile time polymorphism, but question was about input at run time. If input is decided at runtime, which function to get called is also at run time decision. Can someone now plz resonate that why this code represent static / compile time polymorphism? https://sololearn.com/compiler-playground/ceRUzz989vOe/?ref=app P.s. why then same is not decided by compiler for run time polymorphism at time of compilation?

13th Feb 2025, 5:30 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
4 Réponses
+ 1
Run time polymorphism are based on same function for different classes which are solved using virtual functions and compile time polymorphism are based on function overloading and operator overloading. That's the reason both work differently. The given codes inputs will be used in runtime as it waits for the inputs and then it gets compiled and gives the outputs accordingly. Check out the link below to get details about them. https://www.geeksforgeeks.org/compile-time-vs-run-time-polymorphism-difference-in-cpp/
13th Feb 2025, 7:25 AM
Aysha
+ 1
Looking for the same issue. Bumped into your thread. Thanks for creating it. Looking forward for solution. Thanks for the info I will try to figure it out for more. Thanks to this article I can learn more. Expand my knowledge and abilities. Actually the article is very real.
13th Feb 2025, 8:45 AM
michs23
0
Aysha , I am clear about virtual keyword. We can't say that lack of virtual means it is compile time polymorphism as a logical reasoning to the developer. Also, it wait for input and then gets compiled is something wrong.
13th Feb 2025, 11:07 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Ketan Lalcheta I agree about the compilation due to working more on python I got confused with interpretation. Well both runtime and compile type polymorphism has different approaches as runtime for different classes with same function which uses virtual functions there are pure functions with no arguments and one more with arguments. So that's different scenarios. You can't mix it with compile time polymorphism.
13th Feb 2025, 11:20 AM
Aysha