#include<iostream>
using namespace std;
class Person {
public:
int age;
string name;
Person(int age, string name)
{
this->age=age;
this->name=name;
}
int get_age() const;
int inc_age() const;
};
int Person::get_age() const {
return age;
}
int Person::inc_age() const {
this->age++;
}
int main()
{
Person p;
p.age=10;
cout << p.get_age() << endl;
return 0;
}
visual studio 에서는 f5 로 디버깅을 해보시게~ g++ 에서는 -g 넣고 gdb로 디버깅을 해보시게~
저기서 Person p; 선언이 잘못된건가여;?
생성자를 정의해놓고 쓰질않으니 오류가 뜨는거지... 생성자를 정의하면 디폴트 생성자는 사라짐
inc age 함수뒤에 const쓰고 값변경하네
헬좀해줘횽들.. 이거 어케 수정해야할지 모르겠어. 내가 ㅄ인가봐
일단 const 는함수는 클래스 내의 변수값을 변경할수없어서 const쓰면 안되지
그리고 c++에서 string 이라는 변수를 써도 되나?!
1. mutable 선언 하면 const 함수 내에서도 수정 가능.
2. std::basic_string 이라는 개체가 typedef 되어있음