Skip to content

Commit 30e7753

Browse files
committed
operator overloading
1 parent fd660c9 commit 30e7753

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

book/favicon.png

1.64 KB
Loading

book/index.html

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,6 @@ <h1 class="menu-title">Jang</h1>
168168
</div>
169169

170170

171-
<!-- Livereload script (if served using the cli tool) -->
172-
<script type="text/javascript">
173-
var socket = new WebSocket("ws://localhost:3001");
174-
socket.onmessage = function (event) {
175-
if (event.data === "reload") {
176-
socket.close();
177-
location.reload(true); // force reload from server (not from cache)
178-
}
179-
};
180-
181-
window.onbeforeunload = function() {
182-
socket.close();
183-
}
184-
</script>
185-
186171

187172

188173
<!-- Google Analytics Tag -->

book/print.html

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ <h1 class="menu-title">Jang</h1>
391391
<li>
392392
<p>Rust does not allow addition of <code>integer</code> and <code>float</code>. Overload <code>+</code> so that this is possible.</p>
393393
</li>
394+
<li>
395+
<p>Implement custom <code>Drop</code> for a struct <code>Hero</code> that contains a field <code>name</code> of type string.
396+
The <code>drop</code> should print &quot;Oh no !!! Our hero {name} is defeated&quot;. Run the program with just
397+
declaring a variable of type <code>Hero</code>.</p>
398+
</li>
399+
<li>
400+
<p>Create the struct named <code>World</code> that contains the previous named struct <code>Hero</code>, define <code>drop</code>
401+
for it so that it prints &quot;The world ends here !!!&quot;. Observe the order in which <code>World</code> and <code>Hero</code>
402+
contained by it are dropped.</p>
403+
</li>
404+
<li></li>
394405
</ul>
395406
<ul>
396407
<li>
@@ -440,21 +451,6 @@ <h1 class="menu-title">Jang</h1>
440451
</div>
441452

442453

443-
<!-- Livereload script (if served using the cli tool) -->
444-
<script type="text/javascript">
445-
var socket = new WebSocket("ws://localhost:3001");
446-
socket.onmessage = function (event) {
447-
if (event.data === "reload") {
448-
socket.close();
449-
location.reload(true); // force reload from server (not from cache)
450-
}
451-
};
452-
453-
window.onbeforeunload = function() {
454-
socket.close();
455-
}
456-
</script>
457-
458454

459455

460456
<!-- Google Analytics Tag -->

src/chapter_6-operatoroverloading&utility/questions.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@ and `plus` operator to add and subtract complex number.
99
* Create a struct named `Class` that contains the class size, section and grade. Overload
1010
the `>`, `<`, `>=`, `<=`, `==` operators to compare class sizes of various Classes.
1111

12-
* Rust does not allow addition of `integer` and `float`. Overload `+` so that this is possible.
12+
* Rust does not allow addition of `integer` and `float`. Overload `+` so that this is possible.
13+
14+
* Implement custom `Drop` for a struct `Hero` that contains a field `name` of type string.
15+
The `drop` should print "Oh no !!! Our hero {name} is defeated". Run the program with just
16+
declaring a variable of type `Hero`.
17+
18+
* Create the struct named `World` that contains the previous named struct `Hero`, define `drop`
19+
for it so that it prints "The world ends here !!!". Observe the order in which `World` and `Hero`
20+
contained by it are dropped.
21+
22+
*

0 commit comments

Comments
 (0)