42seoul/projects
2024.03.13
Exercise 00: Easy find easyfind ๋ผ๋ ํ
ํ๋ฆฟํจ์๋ฅผ ๊ตฌํํด์ผํ๋ค. ํด๋นํจ์๋ container์ value๋ฅผ ๋ฐ๊ณ container์์ ํด๋น value๊ฐ ์กด์ฌํ๋ค๋ฉด ํด๋นํ๋ value์์น์ iterator๋ฅผ ๋ฐํํ๋ค. ๋ง์ฝ ์กด์ฌํ์ง์๋๋ค๋ฉด error ์ฒ๋ฆฌ ํ์. iterator() typename T::iterator iter; iter = std::find(container.begin(), container.end(), value); std::cout
42seoul/projects
2024.03.13
C++ templates https://jun-13.tistory.com/148 [C++] templates C++ templates ์ฝ๋์ ์ผ๋ฐํ์ ์ฌ์ฌ์ฉ์ ์ํ ๊ฐ๋ ฅํ ๋ฉ์ปค๋์ฆ์ ์ ๊ณตํ๋ ๊ธฐ๋ฅ // templates function template T add(T a, T b) { return a + b; } int main() { // intํ ์ธ์๋ฅผ ๊ฐ๋ ํจ์ ํธ์ถ std::cout moaoh.dev Exercise 00: Start with a few functions what is templates?? // templates function template T add(T a, T b) { return a + b; } int main() { // intํ ์ธ์๋ฅผ ๊ฐ๋ ํจ์ ํธ์ถ std::cout
42seoul/projects
2024.03.13
C++ templates ์ฝ๋์ ์ผ๋ฐํ์ ์ฌ์ฌ์ฉ์ ์ํ ๊ฐ๋ ฅํ ๋ฉ์ปค๋์ฆ์ ์ ๊ณตํ๋ ๊ธฐ๋ฅ // templates function template T add(T a, T b) { return a + b; } int main() { // intํ ์ธ์๋ฅผ ๊ฐ๋ ํจ์ ํธ์ถ std::cout
42seoul/projects
2024.03.13
C++ casts https://jun-13.tistory.com/146 [C++] casts C++ casts c++์๋ ๋ค์ํ ํ ๋ณํ ์ฐ์ฐ์(๋๋ ์บ์คํธ ์ฐ์ฐ์)๊ฐ ์๋ค. static_cast reinterpret_cast dynamic_cast const_cast ์์ ๊ฐ์ด ํฌ๊ฒ 4๊ฐ์ง์ cast๋ค์ด ์กด์ฌํ๋ค. static_cast ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ํ ๋ณํ ์ฐ์ฐ์๋ก, moaoh.dev Exercise 00: Conversion of scalar static_cast ํ์ ๊ฐ์ ํ ๋ณํ์ ์ํํ๋ ๋ฐ ์ฌ์ฉ๋๋ ํ ๋ณํ ์ฐ์ฐ์์ด๋ค. int i = 42; double d = static_cast(i); // int๋ฅผ double๋ก ๋ณํ double d = 3.14; int i = static_cast(d..
42seoul/projects
2024.03.13
C++ casts c++์๋ ๋ค์ํ ํ ๋ณํ ์ฐ์ฐ์(๋๋ ์บ์คํธ ์ฐ์ฐ์)๊ฐ ์๋ค. static_cast reinterpret_cast dynamic_cast const_cast ์์ ๊ฐ์ด ํฌ๊ฒ 4๊ฐ์ง์ cast๋ค์ด ์กด์ฌํ๋ค. static_cast ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ํ ๋ณํ ์ฐ์ฐ์๋ก, ์ปดํ์ผ ์๊ฐ์ ์์ ํ ํ ๋ณํ์ ์ํํฉ๋๋ค. ์ปดํ์ผ๋ฌ๊ฐ ํ์
๊ฒ์ฌ๋ฅผ ์ํํ๋ฉฐ, ์์ ํ์ง ์์ ํ ๋ณํ์ ๋ฐฉ์งํฉ๋๋ค. ์ด๋ฅผ ํตํด ๋ฐ์ดํฐ ์์ค์ ์ค์ผ ์ ์์ต๋๋ค. #include intmain() { double d = 3.14; int i = static_cast(d); // double์ int๋ก ๋ณํ std::cout
42seoul/projects
2024.03.13
๋ฐ๋ณต๊ณผ ์์ธ์ฒ๋ฆฌ (Repetition and Exceptions) https://jun-13.tistory.com/144 [C++] Repetition and Exceptions Repetition and Exceptions๋? ์์ธ ํด๋์ค ํด๋์ค์์์ ์์ธ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ ํ์ฅํ๊ณ ๊ด๋ฆฌํ๊ธฐ ํธํ๊ฒ ๋ง๋๋ ํด๋์ค class Bureaucrat { public: class GradeTooHighException : public std::exception { public: const char *wha moaoh.dev Ex00: Mommy, when I grow up, I want to be a bureaucrat! ์์ธ์ฒ๋ฆฌ ํด๋์ค์ ๋ํ ๊ฐ๋
์ ๋ํด ๊ธฐ์ด์ ์ผ๋ก ๊ณต๋ถํ๋ ํํธ bureaucrat ํด๋์ค co..
42seoul/projects
2024.03.13
Repetition and Exceptions๋? ์์ธ ํด๋์ค ํด๋์ค์์์ ์์ธ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ ํ์ฅํ๊ณ ๊ด๋ฆฌํ๊ธฐ ํธํ๊ฒ ๋ง๋๋ ํด๋์ค class Bureaucrat { public: class GradeTooHighException : public std::exception { public: const char *what() const throw() { return ("error"); } }; **std::exception**์ C++ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ ๊ณตํ๋ ๊ธฐ๋ณธ ์์ธ ํด๋์ค ์์ ๊ฐ์ ํ์์ผ๋ก ์ ์ธํ ์ ์๋ค. #include "Bureaucrat.hpp" intmain() { try { b.setGrade(0); } catch (std::exception &e) { std::cout
42seoul/projects
2023.09.13
interfaces ( ์ธํฐํ์ด์ค ) "ํน์ ๊ธฐ๋ฅ์ ๊ตฌํํ ๊ฒ์ ์ฝ์ํ ์ถ์ ํ์”์ด๋ผ๊ณ ๋ช
์๊ฐ ๋์ด์๋ค. #include class Ihello { public: virtual void print() = 0; }; class korean : public Ihello { public: virtual void print() { std::cout
42seoul/projects
2023.09.13
abstract class (์ถ์ ํด๋์ค) ํ๋ ์ด์์ ์์ ๊ฐ์ ํจ์๋ฅผ ํฌํจํ๊ณ ์๋ ํด๋์ค๋ฅผ ์ถ์ ํด๋์ค๋ผ๊ณ ๋ถ๋ฅธ๋ค. class Test { private: public: virtual void sound() = 0; // ์์๊ฐ์ํจ์ }; class Test { private: public: virtual void sound() = 0; }; class Copy : public Test { public: virtual void sound() { std::cout