Thread: I summarize the initialization places of various variables

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    I summarize the initialization places of various variables

    I summarize the initialization places of various variables, would somebody check if it's correct?

    1,2 or 3 cases will be explained later

    __________________static_________const____________ _static const
    integral____________2____________3________________ ___1 or 2
    non-integral_______ 2____________3_____________________2

    1. declaration place
    Example:
    Code:
    class A{                                                                        
    public:                                                                         
        void foo();                                                                 
        static const int x=1; 
        A(){}                                                                       
    };
    2. out of class
    Example:
    Code:
    class A{                                                                        
    public:                                                                         
        void foo();                                                                 
        static const string s; 
        A(){}                                                                       
    }; 
    
    const string A::s = "";
    3. initialization list
    Example:
    Code:
    class A{                                                                        
    public:                                                                         
        void foo();                                                                 
        const int x; 
        A():x(1){}                                                                       
    };
    Last edited by meili100; 04-15-2008 at 05:02 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Sounds right.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Father and Son Variables
    By khdani in forum Linux Programming
    Replies: 3
    Last Post: 11-28-2008, 06:42 PM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Creating local variables in a program?
    By fl0at in forum C Programming
    Replies: 5
    Last Post: 01-04-2008, 07:34 PM
  5. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM