컴공 일기256
게시글 주소: https://orbi.kr/00070757393
STL의 string을 흉내내고 있습니다.
되돌아 온 객체 지향의 향기… 익숙하고도 준엄하군요.
사실 결함이 있다면 선언 / 정의를 분리시켜야 하는데, 아이패드에선 그걸 지원하지 않아서
한 헤더 파일에 선언과 정의를 모두 적고 있습니다… 씁슬하네요.
#pragma once
#include <iostream>
using namespace std;
class CMystring
{
public:
CMystring();
~CMystring();
//멤버 변수에 포인터가 있으므로 Deep Copy를 반드시 지원해야 한다.
CMystring(const CMystring&);
const char* getData() const;
void setData(const char*);
const size_t getLength() const;
void operator=(const CMystring& rhs);
private:
char*m_pszData = nullptr;
size_t length = 0;
};
CMystring::CMystring()
{
cout << "CMystring()" << endl;
}
//Deep Copy
CMystring::CMystring(const CMystring& rhs)
{
this->setData(rhs.m_pszData);
}
CMystring::~CMystring()
{
cout << "~CMystring()" << endl;
delete[] m_pszData;
}
void operator=(const CMystring& rhs)
{
this->setData(rhs.m_pszData);
}
const char* CMystring::getData() const
{
return m_pszData;
}
void CMystring::setData(const char* pParam)
{
//setData()가 여러번 호출될 경우, m_pszData가 null이 아닐 수도 있다.
if(m_pszData != nullptr)
delete[] m_pszData;
size_t length = strlen(pParam);
m_pszData = new char[length + 1];
this->length = length;
strcpy(m_pszData, pParam);
}
const size_t CMystring::getLength() const
{
return this->length;
}
0 XDK (+0)
유익한 글을 읽었다면 작성자에게 XDK를 선물하세요.
-
님들 진학 텔그 메가 다 결제 했는데... 각각 어느 정도 믿어도 됨???? 11
ㅈㄱㄴ... 답 좀 해줘.... ㅠㅠㅠㅠㅠ 절박합니다 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ
-
메가 설명회 0
대충 몇시간이나 진행하나요?
-
근제 왜 내 알고리즘에 뜬거지...
-
부모님이 위험하다는데 해도될까
-
그냥 훌리 억까 다 좋음 여러 사람 생각 들어보는중이라
-
또 갔어...
-
개띵곡 2
https://youtu.be/1-bMyangTew?si=C04yxlL-8C_j8Xpk
-
문과기준입미다. 1.캠퍼스 전체가 언덕이라 다리근육발달 ㅆㄱㄴ 2.문과도 코딩마스터...
-
.
-
전 61 ㄹㅇ 어디서 틀린거지? 진짜 마지막에 다 구하고 싹다 더할때 계산실수한건가
-
재수하려고 하는데 ~6월 정도 까지 독재 + 단과 하고 반수 재종반 들어가는거...
-
선착맞팔9 5
ㄱㄱ
첫번째 댓글의 주인공이 되어보세요.