This demonstrates a C++ initialization list sample source code

(Last Updated On: June 15, 2010)

This works for initialization list
class A {
int x;
string s;
const int y;
A(int x1, string s1, const int y1): x(x1), s(s1), y(y1) {}
void hi() { x=5; } //if you change y here , it will fail due to y //being const
int main() {
int s;
double arr[3] = {1.0,12.0,5.0};
s = sum (arr,3);
cout << "sum: "<< s << endl; // prints int h=5; A* a=new A(10,"h", h); a->hi();
return 0;
class A
A() {} //this ctr must be public not set private as default


NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.


Check NEW site on stock forex and ETF analysis and automation

Scroll to Top