cpp:stl:intro
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cpp:stl:intro [2020/05/29 08:16] – removed gthanos | cpp:stl:intro [2023/05/30 18:30] (current) – [Η κλάση Student] gthanos | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Standard Template Library (STL) ====== | ||
| + | |||
| + | H //Standard Template Libray (STL)// είναι βιβλιοθήκη της C++ που αποτελεί αναπόσπαστο τμήμα της // | ||
| + | |||
| + | Βασικό χαρακτηριστικό της //STL// είναι ότι οι κλάσεις (// | ||
| + | |||
| + | ===== Η κλάση Student ===== | ||
| + | |||
| + | Στα παραδείγματα που ακολουθούν | ||
| + | |||
| + | <code cpp Student.hpp> | ||
| + | #ifndef _STUDENT_HPP_ | ||
| + | #define _STUDENT_HPP_ | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | class Student { | ||
| + | private: | ||
| + | char *name; | ||
| + | int aem; | ||
| + | public: | ||
| + | Student(); | ||
| + | Student(const char *name, int aem); | ||
| + | Student(const Student& | ||
| + | ~Student(); | ||
| + | | ||
| + | char* getName() const; | ||
| + | int getAEM() const; | ||
| + | void setName(char*); | ||
| + | void setAEM(int); | ||
| + | | ||
| + | friend std:: | ||
| + | bool operator> | ||
| + | bool operator< | ||
| + | Student& | ||
| + | }; | ||
| + | |||
| + | Student:: | ||
| + | this-> | ||
| + | strcpy(this-> | ||
| + | this-> | ||
| + | std::cerr << "Argu Construct : " << *this << std::endl; | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | name = new char [strlen(st.name) + 1]; | ||
| + | strcpy(name, | ||
| + | aem = st.aem; | ||
| + | std::cerr << "Copy Construct : " << *this << std::endl; | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | this-> | ||
| + | this-> | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | if(name != nullptr) { | ||
| + | std::cerr << " | ||
| + | delete []name; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | char* Student:: | ||
| + | return name; | ||
| + | } | ||
| + | |||
| + | int Student:: | ||
| + | return aem; | ||
| + | } | ||
| + | |||
| + | void Student:: | ||
| + | this-> | ||
| + | delete this-> | ||
| + | this-> | ||
| + | strcpy(this-> | ||
| + | } | ||
| + | |||
| + | void Student:: | ||
| + | this-> | ||
| + | } | ||
| + | |||
| + | Student& | ||
| + | if(name != nullptr) | ||
| + | delete name; | ||
| + | name = new char [strlen(st.name) + 1]; | ||
| + | strcpy(name, | ||
| + | aem = st.aem; | ||
| + | std::cerr << "Copy : " << *this << std::endl; | ||
| + | return *this; | ||
| + | } | ||
| + | |||
| + | std:: | ||
| + | if(st.name != nullptr) | ||
| + | out << st.name << " " << st.aem; | ||
| + | return out; | ||
| + | } | ||
| + | |||
| + | bool Student:: | ||
| + | if(aem > st.aem) | ||
| + | return true; | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | bool Student:: | ||
| + | if(aem < st.aem) | ||
| + | return true; | ||
| + | return false; | ||
| + | } | ||
| + | #endif | ||
| + | </ | ||
cpp/stl/intro.1590740185.txt.gz · Last modified: 2020/05/29 07:16 (external edit)
