일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- htmlspecialchars
- sql injection
- IF문
- object
- 포인터
- 메소드
- document
- 조건문
- xss game
- xss game 풀이
- 사칙연산
- python
- Pwndbg
- suninatas 풀이
- burp suite
- element 조회
- jQuery
- property
- window
- blind sql injection
- github
- 백준 알고리즘
- 김성엽 대표님
- 자바스크립트
- 파이썬
- 함수
- lord of sql injection
- 백준 파이썬
- 배열
- 객체
Archives
- Today
- Total
power-girl0-0
[ C++ ] 생성자와 소멸자를 이용한 예제 본문
728x90
생성자와 소멸자에 대한 개념은 아래 주소를 참고해주세요 : )
( 주소 : 2021.03.23 - [언어/C++] - [ C++ ] 클래스 & 객체)
[ C++ ] 클래스 & 객체
클래스 & 객체 개요 클래스 객체를 만들어내기 위해 정의된 설계도, 틀이다. 클래스는 객체가 아니다. 클래스 내부에는 멤버변수와 멤버 함수 선언이 가능하다. 객체 객체는 생성될 때 클래
power-girl0-0.tistory.com
아래 예제는 생성자를 만들어, 이름과 나이를 입력받는 예제이다.
#include <iostream>
#include <string.h>
using namespace std;
class Person{
string name;
int age;
public:
Person();
Person(string n, int a);
Person(string n);
string getName();
int getAge();
~Person();
};
Person::Person(){
name = "bear";
age = 20;
}
Person::Person(string n){
name = n;
age = 24;
}
Person::Person(string n, int a){
name = n;
age = a;
}
Person::~Person(){
cout<<name<<"님의 기록이 삭제되었습니다."<<endl;
}
string Person::getName(){
return name;
}
int Person::getAge(){
return age;
}
int main(){
Person ps;
Person pa("cat",22);
Person pt("dog");
cout<<"이름 : "<<ps.getName()<<", 나이 : "<<ps.getAge()<<endl;
cout<<"이름 : "<<pa.getName()<<", 나이 : "<<pa.getAge()<<endl;
cout<<"이름 : "<<pt.getName()<<", 나이 : "<<pt.getAge()<<endl;
}
728x90
'언어 > C++' 카테고리의 다른 글
[ C++ ] 계산기 ( 클래스를 이용한 예제 ) (0) | 2021.03.23 |
---|---|
[ C++ ] 잔액 구하기 ( 클래스를 이용한 예제 ) (0) | 2021.03.23 |
[ C++ ] 클래스를 이용하여, 사각형 면적과 둘레 구하기 (0) | 2021.03.23 |
[ C++ ] 클래스 & 객체 (0) | 2021.03.23 |
[ C++ ] 해밍코드 거리 구하기 (0) | 2021.03.23 |
Comments