Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bracket Operator.

Similar presentations


Presentation on theme: "Bracket Operator."— Presentation transcript:

1 Bracket Operator

2 Code Trace // main.cpp ... int main() { Fraction f(3,4);
cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); }

3 Code Trace main:: f m_Numerator: 3 m_Denominator: 4 // main.cpp ...
int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f m_Numerator: 3 m_Denominator: 4

4 Code Trace main:: f m_Numerator: 3 m_Denominator: 4 // main.cpp ...
int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f m_Numerator: 3 m_Denominator: 4

5 Code Trace main:: f operator[]::index m_Numerator: 3 m_Denominator: 4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f operator[]::index m_Numerator: 3 m_Denominator: 4 5

6 Code Trace main:: f operator[]::index m_Numerator: 3 m_Denominator: 4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f operator[]::index m_Numerator: 3 m_Denominator: 4 5

7 Code Trace main:: f output buffer m_Numerator: 3 m_Denominator: 4 4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer m_Numerator: 3 m_Denominator: 4 4

8 Code Trace main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4

9 Code Trace main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4

10 Code Trace main:: f output buffer operator[]::index m_Numerator: 3
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer operator[]::index m_Numerator: 3 m_Denominator: 4 _4 1

11 Code Trace main:: f output buffer operator[]::index m_Numerator: 3
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer operator[]::index m_Numerator: 3 m_Denominator: 4 _4 1

12 Code Trace main:: f output buffer m_Numerator: 3 m_Denominator: 4 4_4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer m_Numerator: 3 m_Denominator: 4 4_4

13 Code Trace main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4_4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4_4

14 Code Trace main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4_4
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer m_Numerator: 3 m_Denominator: 4 _4_4

15 Code Trace main:: f output buffer operator[]::index m_Numerator: 3
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer operator[]::index m_Numerator: 3 m_Denominator: 4 _4_4

16 Code Trace main:: f output buffer operator[]::index m_Numerator: 3
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer operator[]::index m_Numerator: 3 m_Denominator: 4 _4_4

17 Code Trace main:: f output buffer operator[]::index m_Numerator: 3
// main.cpp ... int main() { Fraction f(3,4); cout<<f[0]<<“ ”<<f[1]<<“ ”<<f[5]; // fraction.cpp int Fraction::operator [] (const int index)     return (index==0 ? m_Numerator : m_Denominator); } main:: f output buffer operator[]::index m_Numerator: 3 m_Denominator: 4 3_4_4

18 Overloaded Wookie

19 End of Session


Download ppt "Bracket Operator."

Similar presentations


Ads by Google