initialized a reference member of a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michaelmaowang
    New Member
    • Oct 2011
    • 1

    initialized a reference member of a class

    How can I initialize a reference member to another member of a class? If I do this I got a compile error:

    Code:
    class A {
    public: A():b(0)),c(b){}
    
    private:
             int b;
             int &c;
    }
    Last edited by Banfa; Oct 14 '11, 10:30 AM. Reason: Added [code]...[/code] tags round the code
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What you have is OK after you fix your syntax errors.

    a) there is an unmatched ) in the A constructor
    b) the class declaration must end in a ;

    Comment

    Working...