Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cv2
#include <iostream> using std::cout; struct TVector { size_t iSize = 0; size_t iCapacity = 0; double *iData = nullptr; }; double Get(TVector &aVec, size_t aIndex) { if(aVec.iSize <= aIndex) throw "Index mimo vektor"; return aVec.iData[aIndex]; } void Set(TVector &aVec, size_t aIndex, double aVal) { if(aVec.iSize <= aIndex) throw "Index mimo vektor"; aVec.iData[aIndex] = aVal; } void AllocVector(TVector &aVec, size_t aSize) // Neni potreba kontrolovat, jestli aVec == nullptr. { // aVec je totiz reference. if(aVec.iData) // aVec je platny https://i.imgflip.com/4hrk9k.jpg it aint much but its honest work throw "Jiz naalokovano"; //while(true) // test bad_alloc // new double[100000000ul]; // aVec.iData = new double[aSize]; aVec.iSize = aSize; aVec.iCapacity = aSize; } void DeallocVector(TVector &aVec) { delete[] aVec.iData; aVec.iSize = aVec.iCapacity = 0; } int main() { TVector v; try { AllocVector(v, 10); Set(v, 9, 5.0); cout << Get(v, 9) << '\n'; } catch(char aStr[]) { cout << "Vyjimka: " << aStr << '\n'; } catch(std::bad_alloc exc) { cout << "Vyjimka bad_alloc: " << exc.what() << '\n'; // exc.what() ... kde vznikla vyjimka } catch(...) { cout << "Obecna vyjimka\n"; } DeallocVector(v); return(0); } //Pajoš - musim rici, ze toto byla asi nejlepsi hodina z celych online prednasek a cvik :D //xcharv19 taky souhlas s Pajoš // Petr Safranek - //Anonym - // Samko Janecek - // Tobias - // Marketa- //Jakub Lukaszczyk - Pajoš souhlasím // Stejsky: Potřebuji na záchod. :'( ...už ne. Nemáte niekto hadr ? ano, kam mam donest //nádhera //Timotej - //Microsoft <3 -- miluju tě Pety ????????
run
|
edit
|
history
|
help
0
c++
msvc set-terminate
multiplie linked list numbers
cv5
C++ string format
throwing Copyable versus throwing MoveOnly
rvalue lifetime
Increment pointer to struct
Not Common Numbers
hangman