본문 바로가기

객체지향6

[C++] Object-Oriented Programming: Interface (ENG) Multiple Inheritance // Faculty.h class Faculty { }; // Student.h class Student { }; // TA.h class TA : public Student, public Faculty { }; // Main.cpp TA* myTA = new TA(); The constructors are called in the order of the parent class in the child class declaration. (Regardless of the order of the initialiation list.) problem 1: Compiler doesn't know which function is supposed to be called. // Ma.. 2022. 1. 2.
[C++] Object-Oriented Programming: Polymorphism (ENG) Memory of the Member Function Member functions are allocated to the memory only once while compliling. Function Overriding // Animal.h class Animal { public: void Speak(); } // Animal.cpp void Animal::Speak() { std::cout 2022. 1. 2.
[C++] Object-Oriented Programming: Inheritance (ENG) Difference between Java and C++ // Java public class Cat extends Animal { private String Name; public Cat(int age, String name) { super(age); // calls Animal(int age) Name = name; } } // C++ class Cat : public Animal { public: Cat(int age, const char* name); private: char* mName; }; Cat::Cat(int age, const char* name) : Animal(age) { size_t size = string(name) +1; mName = new char[size]; strcpy(.. 2022. 1. 2.
[C++] Object-Oriented Programming : Overloading (ENG) Copy Constructor How to write a copy constructor: ( const & ); // Vector.h class Vector { public: Vector(const Vector& other); // copy constructor private: int mX; int mY; }; // Vector.cpp Vector::Vector(const Vector& other) : mX(other.mX) , mY(other.mY) { } // Main.cpp Vector a; // call the constructor with no parameter Vector b(a); // call the copy oconstructor There is also an implicit copy c.. 2022. 1. 2.
[C++] Object-Oriented Programming : Class (ENG) Access Modifier public : accessible to anyone protected : accessible from child classes private : accessible only from the class (not the object) The default for access permissions is private. class SomeClass { public: int PublicMember; protected: int mProtectedMember; // m for member variables private: int mPrivateMember1; int mPrivateMember2; }; Create and Delete an Object // create in stack m.. 2022. 1. 2.
[프로그래밍언어론] 과제 2 : OOP 특성을 가진 언어로 구현하기 (Go 사용) 문제 Write a corresponding program for the given example below (in C++, Java and Python) using ONE of the other languages that have different OOP traits such as separation of types from their implementations (e.g. Go), multimethods (e.g. Julia), implementation-only inheritance thru mixin (e.g. Scala, Crystal), prototypes and delegation (e.g. Lua, Io), etc. You will be given better score if you can.. 2020. 12. 20.