ccplusplus.com
Learn C, C++ Concepts
Friday, February 24, 2012
array initialization in class in c++
/************************************************************************* * File : array-ini-in-class.cpp * Author : Saurabh Gupta * Desc : array-ini-in-class.cpp * Source : http://www.ccplusplus.com/p/c_15.html * Created : 9:37 AM Friday, February 24, 2012 * Note : *************************************************************************/ #include
using namespace std; class Abc{ private: static const int arr[3]; static const double var = 3.14; public: Abc() { for(int i=0; i<3; ++i) { cout << arr[i] << endl; } } ~Abc () { } }; const int Abc::arr[3] = {1,2,3}; int main() { Abc aa; return(0); } /* * OUTPUT * [sgupta@rhel6x86 cpp]$ c++ array-ini-in-class.cpp -o array-ini-in-class [sgupta@rhel6x86 cpp]$ ./array-ini-in-class 1 2 3 [sgupta@rhel6x86 cpp]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment