0% found this document useful (0 votes)
5 views

C++ Concepts and Examples

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

C++ Concepts and Examples

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Define Function Overloading

Function Overloading is a feature in C++ that allows you to have multiple functions with the same

name but different parameters. This means that depending on the arguments passed, a different

version of the function is called. It helps improve readability and maintainability by allowing functions

that perform similar tasks to have the same name.

Example:

void print(int i) {

cout << "Integer: " << i << endl;

void print(double f) {

cout << "Float: " << f << endl;

void print(string s) {

cout << "String: " << s << endl;

In this example, the print function is overloaded with different parameter types (int, double, string).

2. Static Data Members and Static Member Functions

Static data members are shared among all instances of a class. They are declared using the 'static'

keyword and exist independently of any objects. Static member functions, also declared with 'static',

can access only static data members and are called using the class name rather than object

instances.

Example:

class Example {

public:

static int count;


Example() { count++; }

static int getCount() { return count; }

};

int Example::count = 0;

In this example, 'count' is a static member, so it's shared among all objects of the class. The static

function getCount() returns this shared value.

You might also like