- 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É:**