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

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...