C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 18)
18.
Which of the following correctly describes overloading of functions?
Virtual polymorphism
Transient polymorphism
Ad-hoc polymorphism
Pseudo polymorphism
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
36 comments Page 3 of 4.

Aniket said:   1 decade ago
Ad-hoc polymorphism allows functions with the same name act differently for each type. For example, given two ints and the + operator, it adds them together. Given two std::strings it concatenates them together. This is called overloading.

Here is a concrete example that implements function add for ints and strings,

#include <iostream>
#include <string>

int add(int a, int b) {
return a + b;
}

std::string add(const char *a, const char *b) {
std::string result(a);
result += b;
return result;
}

int main() {
std::cout << add(5, 9) << std::endl;
std::cout << add("hello ", "world") << std::endl;
}
Ad-hoc polymorphism also appears in C++ if you specialize templates. Returning to the previous example about max function, here is how you'd write a max for two char *,

template <>
const char *max(const char *a, const char *b) {
return strcmp(a, b) > 0 ? a : b;
}

Sanil said:   1 decade ago
Can anyone explain more about Ad-hoc polymorphism, transient and psuedo polymorphism ?

Rupali said:   1 decade ago
What is mean by transient and pseudo polymorphism ?

Kalpana said:   1 decade ago
What is transient and pseudo polymorphism ? and it is a type polymorphism ? then explain more about Ad-hoc polymorphism ?

Shweta said:   1 decade ago
In programming languages, ad-hoc polymorphism is a kind of polymorphism in which polymorphic functions can be applied to arguments of different types, because a polymorphic function can denote a number of distinct and potentially heterogeneous implementations depending on the type of argument(s) to which it is applied. It is also known as function overloading or operator overloading.

Pavithra said:   1 decade ago
Ad-hoc polymorphism behaves differently for different data types with same name.

Can anyone explain about pseudo polymorphism and transient polymorphism?

Supreet kaur said:   1 decade ago
Is Ad-hoc polymorphism and overloading is the same thing?

Vicky said:   1 decade ago
What is meant by Ad-hoc polymorphism, transient and psuedo polymorphism?

Ramesh said:   1 decade ago
What is meant by Ad-hoc polymorphism, transient and pseudo polymorphism?

Sudhanshu said:   1 decade ago
The Four Polymorphisms in C++.

When people talk about polymorphism in C++ they usually mean the thing of using a derived class through the base class pointer or reference, which is called subtype polymorphism. But they often forget that there are all kinds of other polymorphisms in C++, such as parametric polymorphism, ad-hoc polymorphism and coercion polymorphism.

These polymorphisms also go by different names in C++,

Subtype polymorphism is also known as runtime polymorphism.

Parametric polymorphism is also known as compile-time polymorphism.

Ad-hoc polymorphism is also known as overloading.

Coercion is also known as (implicit or explicit) casting.

Ad-hoc polymorphism allows functions with the same name act differently for each type. For example, given two 'int' values and the '+' operator, it adds them together. Given two 'std::strings' it concatenates them together. This is called overloading.


Post your comments here:

Your comments will be displayed after verification.