Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cv3
#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); } //https://rextester.com/live/DFT8522 //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 Saly - //Microsoft <3 -- miluju tě Pety ????????
run
|
edit
|
history
|
help
0
Zero length array as a class member
MSVC-IsBaseOf
#21.2
C++ Macro overload
regex select, find
#27
Multiple inheritance of empty classes - sizeof
Build char string (multibyte) with wchar
Copy double[2][3] into vector<vector<double>>
seh exception in constructor memory leak