Files
PPC/poznamky z hodin/Cviceni 2.md
Lugaricci 56b536368b pridani poznamek s conteinery, restrukturalizace, oprava kodu
pridani poznamek ke containerum zatim pouze s vectory
poznamky z hodim maji ted vlastni podslozku
lehka oprava kodu vsede mozne, hlavne pridani cpp pro lepsi cteni a
oprava drobnych chybek
2026-03-06 15:30:21 +01:00

53 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- 26. 2 - čtvrtek 11:00
- dnes: třídy a objekty, public/protected/private, constructor/destructor
# Konstruktory
- můžu přetěžovat, ale **POZOR**:
```
TridaA(void) //constructor pro inicializaci promenne
{
this->a = 0;
this->b = 0;
this->c = 0;
std::cout << "Byl zavolan konstruktor bez arg." << std::endl;
}
TridaA(int a) //inicializace z argumentu constructoru
{
this->a = a;
this->b = 0;
this->c = 0;
std::cout << "Byl zavolan konstruktor s arg." << std::endl;
}
TridaA(int a, int b = 42, int c = 64)
{
this->a = a;
this->b = b;
this->c = c;
}
```
Chyby kompilatoru:
```
main.cpp: In function int main():
main.cpp:44:16: error: call of overloaded TridaA(int) is ambiguous
44 | TridaA obj1(1); //inicializujeme objekt
| ^
main.cpp:44:16: note: there are 4 candidates
main.cpp:31:5: note: candidate 1: TridaA::TridaA(int, int, int)
31 | TridaA(int a, int b = 42, int c = 64)
| ^~~~~~
main.cpp:23:5: note: candidate 2: TridaA::TridaA(int)
23 | TridaA(int a) //inicializace z argumentu constructoru
| ^~~~~~
main.cpp:3:7: note: candidate 3: constexpr TridaA::TridaA(const TridaA&)
3 | class TridaA
| ^~~~~~
main.cpp:3:7: note: candidate 4: constexpr TridaA::TridaA(TridaA&&)
```
- **MUSÍ TO BÝT JEDNOZNAČNÉ:**