관리 메뉴

moozi

c++ Student클래스 본문

카테고리 없음

c++ Student클래스

moozi 2015. 9. 15. 14:08

#include <iostream>
#include <string>
using namespace std;

class Student{
private:
 string name;
 int age;
 string address;
public:
 Student() { }
 Student(string n) {
  name = n;
 }
 string  getName() {
  return name;
 }
 void setName(string n) {
  name = n;
 }
 int getAge() {
  return age;
 }
 void setAge(int a) {
  age = a;
 }
 string  getAddress() {
  return address;
 }
 void setAddress(string a) {
  address = a;
 }
};

int main() {
 //홍길동 인스턴스생성
 Student *hgd = new Student("홍길동");
 cout << "hgd의 이름 : " << hgd->getName() << endl;
 hgd->setAge(30);
 cout << "hgd의 나이 : " << hgd->getAge() << endl;

 delete hgd; // 생략하면 메모리누수 가능성이 커짐.

 return 0;
}

Comments