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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...