Pages

Thursday, May 29, 2025

A. Create a C++ program that demonstrates function overloading.

 #include <iostream>

#include <string>

#include <vector>

using namespace std;



// Function overloading - example



class Print {

public:

    void show(int x) {

        cout << "int : "<< x << endl;

    }





    void show(string str) {

        cout << "str: " << str << endl;

    }





    void show(string str2) { // <--- This is the problem ( can't put two functions
under a class when it comes to function overloading....

        cout << "str2: " << str2 << endl;

    }

};





int main() {

    Print ob1;



    ob1.show(45);

    ob1.show("apna college");

    ob1.show("Debadatta Patra");



    return 0;

}

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...