1. const fields - Intialization List #

Created Saturday 11 January 2020

To solve this problem, we need to use initialization lists.


Syntax

class A{
	int a, b;
	const string c;
	int d[4];
	...
	void f() : a(2), b(a), c("Sanjar"), d{1,2,3,4} // intialization list
	{
		...
	}
	...
};

Use case:

  1. If we want a const data member.
  2. If our class has reference data members. (Both need to be declarized).