General rulse
~
Aaaaand... OPEN!
Turn-in directory : ex00/
Files to turn in : Makefile, main.cpp, ClapTrap.{h, hpp}, ClapTrap.cpp
Forbidden functions : None
The class will be called ClapTrap, and will have the following private attributes, initialized to the specified values:
In all of these functions, you have to display something to describe what happens.
ClapTrap attacks , causing points of damage!
The constructor and destructor must also display something, so people can see they have been called.
Turn-in directory : ex01/
Files to turn in : Files from previous exercise + ScavTrap.{h, hpp},
ScavTrap.cpp
Forbidden functions : None
아놔 작성하던거 날아갔다
크롬 왜이래 로그인 !!
로그인 확인 하자..
다중상속부터 ex03 부터 정리
화나서 배끼기
이번 과제에서는 클래스의 상속에 관한 내용을 다루게된다.
ex00에서는 Module 03에서 계속해서 사용할 기초 클래스인 ClapTrap을 구현하면 된다.
Orthodox Canonical Form 형식에 맞춰 클래스를 정의하고 과제의 요구사항대로 멤버변수는 private, 멤버함수는 public으로 선언한다.
https://git.42l.fr/pohl/cpp42/src/branch/master/cpp03/ex00/incs/ClapTrap.hpp
위 예시에선 인자 없이 생성자 사용하지 못하게 생성자를 private으로 선언해 놓았음 (디폴트생성자를 막아놨다)
ex00에서 구현한 ClapTrap 클래스를 상속한 ScavTrap 클래스를 구현하면 된다.
ex00에서는 ClapTrap의 멤버변수를 private으로 선언했었지만 ex01에서부터는 상속이 이루어지기 때문에 유도 클래스에서 기초 클래스의 멤버변수에 접근할 수 있도록 위해 ClapTrap의 멤버변수를 모두 protected로 수정한다.
ClapTrap과 마찬가지로 Orthodox Canonical Form 형식에 맞춰 ClapTrap을 public으로 상속받는 ScavTrap 클래스를 정의하고 생성자에서 ClapTrap의 생성자도 호출해준다.
마지막으로 ScavTrap 클래스만의 특수 기능인 guardGate() 함수를 정의해주면 된다.
private의 경우 어떠한 경우라도 같은 클래스 안에서만 접근 가능
protected는 private과 public의 중간. 상속받은 클래스 내에서는 접근 가능하지만 그 외의 경우는 접근 불가능.
class Derived : public Base
상속 할 때 앞에 붙는 public, private protected 차이점
public: 기반 클래스에서 정해진 범위 그대로 가져옴
protected: 기반 클래스에서 public으로 설정된 것을 protected로 받아옴
private: 기반 클래스에 있던 모든 범위를 private으로 바꿈
class ScavTrap : virtual public ClapTrap
{
...
};
class FragTrap : virtual public ClapTrap
{
...
};
class DiamondTrap : public ScavTrap, public FragTrap
{
...
};
마지막으로 DiamondClap 클래스만의 특수 기능인 whoAmI() 함수를 정의해주면 된다.
-Wshadow, -Wno-shadow option
Wshadow option: 지역변수가 다른 지역변수, 매개변수 등(shadow) 덮는 경우 Warning이 발생
이것은 선언된 변수명을 다른 scope에서 다시 선언한 경우 경고를 발생시킨다.