Skip to content

Commit 5bb3871

Browse files
Sebastien PonceSebastien Ponce
Sebastien Ponce
authored and
Sebastien Ponce
committed
Adding a slide on chaining operators
1 parent 376e6da commit 5bb3871

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: talk/objectorientation/operators.tex

+22
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
\end{block}
9595
\end{frame}
9696

97+
\begin{frame}[fragile]
98+
\frametitlecpp[98]{Chaining operators}
99+
\begin{block}{In general, return a reference to the left value}
100+
\begin{cppcode}
101+
struct Complex {
102+
float m_real, m_imaginary;
103+
Complex& operator=( const Complex& other ) {
104+
m_real = other.m_real;
105+
m_imaginary = other.m_imaginary;
106+
return *this;
107+
}
108+
};
109+
Complex c1{2.f, 3.f};
110+
Complex c2, c3;
111+
// right to left associativity
112+
c3 = c2 = c1;
113+
// left to right associativity
114+
std::cout << c1 << c2 << c3 << std::endl;
115+
\end{cppcode}
116+
\end{block}
117+
\end{frame}
118+
97119
\begin{frame}[fragile]
98120
\frametitlecpp[98]{Friend declarations}
99121
\begin{block}{Concept}

0 commit comments

Comments
 (0)