Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit abce4fd

Browse files
Sebastien Poncesponce
Sebastien Ponce
authored andcommitted
Adding a slide on chaining operators
1 parent b95492b commit abce4fd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎talk/objectorientation/operators.tex

Lines changed: 22 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /