Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lectures/2026-03-05-PA2-intro/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ \section{OOP}
\begin{minted}[fontsize=\small]{C}

int create_player(player_t *player) {
player.name = malloc(...);
player.health = 3;
player.damage = 5;
player.state = ON_GROUND;
player->name = (char*)malloc(...);
Comment thread
marekvospel marked this conversation as resolved.
player->health = 3;
player->damage = 5;
player->state = ON_GROUND;

return 0;
}
Expand Down Expand Up @@ -196,8 +196,8 @@ \section{OOP}
return player;
}
void Player::del() {
delete player.name;
player.name = nullptr;
delete[] name;
name = nullptr;
}
\end{minted}
\end{column}
Expand Down Expand Up @@ -232,7 +232,7 @@ \section{OOP}
Player &heal(unsigned int amount) {
unsigned int newhealth = this->health + amount;
if (newhealth > 3) {
return;
return *this;
}
if (newhealth == 0) {
printf("Player died!\n");
Expand Down Expand Up @@ -322,7 +322,7 @@ \section{OOP}
class Player {
...
~Player() {
delete this->name;
delete[] this->name;
this->name = nullptr;
}
}
Expand Down Expand Up @@ -427,7 +427,7 @@ \section{Něco více k C++}
int main() {
int *numptr = new int(1);
int *myarr = new int[5]{1, 2, 3};
Player *plr = new Player();
Player *plr = new Player(3, 2);

delete numptr;
delete[] myarr;
Expand Down Expand Up @@ -490,15 +490,15 @@ \section{Něco více k C++}

\begin{minted}{Cpp}
int main() {
Player p = Player();
Player p = Player(3, 4);

// Co dělá bin. operátor +=?
// Zkracuje nám zápis nějáké funkce
p += 2;
// Může to být to samé jako
// plusequals(p, 2)

// POZOR NA PRIORITĚ OPERACÍ
// POZOR NA PRIORITU OPERACÍ
// (* má větší prioritu než +,
// i když jejich chování prohodíme)
}
Expand All @@ -513,7 +513,7 @@ \section{Něco více k C++}
class Player {
...
Player &operator +=(unsigned int amount) {
this.heal(amount);
this->heal(amount);
return *this;
}
bool operator +=(const Player &other) const {
Expand Down