What does the ":" mean in the following statement?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jennifer Helle
    New Member
    • Dec 2010
    • 2

    #1

    What does the ":" mean in the following statement?

    class FloatingLeg
    {
    public:
    FloatingLeg(map <double, double> floatLegRate, double floatLegBasis, int payFrequency)
    :floatLegRate_( floatLegRate), floatLegBasis_( floatLegBasis), payFrequency_(p ayFrequency){}

    ....}
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    Jennifer,

    What you are looking at there is an initialization list.

    The class has member variables called

    floatLegReate_, floatLegBasis_ , and payFrequency_

    What you are doing is initializing these member variables to the arguments sent into the constructor. This way of constructing your class is more efficient than doing this.

    Code:
    class FloatingLeg
    {
    public:
    FloatingLeg(map<double, double> floatLegRate, double floatLegBasis, int payFrequency)
    {
    floatLegRate_ = floatLegRate;
    floatLegBasis_ = floatLegBasis;
    payFrequency_ = payFrequency;
    }
    };

    Comment

    • Jennifer Helle
      New Member
      • Dec 2010
      • 2

      #3
      Understood. Thank you very much.

      Comment

      Working...