개발/스타일 가이드
나만의 코딩 스타일 가이드 (계속 추가)
-=HaeJuK=-
2024. 6. 18. 15:00
728x90
반응형
1. 클래스
- SIZE 고정 변수의 모임(STRUCT)을 제외하고 모든건 CALSS화 시킨다.
// 허용
struct stMyStruct
{
int nCount;
char szName[100];
char szPhone[100];
};
//금지 --> CLASS화
struct stMyStruct
{
int nCount;
std::string ssName;
std::string ssPhone;
myClass myInfo;
};
class MyInfo
{
public:
MyInfo();
MyInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
private:
int nCount;
std::string ssName;
std::string ssPhone;
};
- 해더 가드
윈도우만 지원하면 #Pragma Once 만 사용
남어지 #ifndef __MYCLASS_H__ #define __MYCLASS_H__ #endfi //~ __MYCLASS_H__ 사용한다.
// Windows Os 전용 CLASS
#pragma once
class MyInfo
{
public:
MyInfo();
MyInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
private:
int nCount;
std::string ssName;
std::string ssPhone;
};
// Multi Os CLASS
#ifndef __MY_INFO_CLASS_H__
#define __MY_INFO_CLASS_H__
class MyInfo
{
public:
MyInfo();
MyInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
private:
int nCount;
std::string ssName;
std::string ssPhone;
};
#endif // !__MY_INFO_CLASS_H__
- 맴버 변수는 무조건 private에 선언한다.
#ifndef __MY_INFO_CLASS_H__
#define __MY_INFO_CLASS_H__
class MyInfo
{
public:
MyInfo();
MyInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
public:
int nPosition; // 금지
private:
int nCount;
std::string ssName;
std::string ssPhone;
};
#endif // !__MY_INFO_CLASS_H__
- 맴버 변수
- HAS-A 관계를 우선시 한다.
#ifndef __MY_PHONEINFO_CLASS_H__
#define __MY_PHONEINFO_CLASS_H__
class MyPhoneInfo
{
public:
MyPhoneInfo();
MyPhoneInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
private:
int nCount;
std::string ssName;
std::string ssPhone;
};
#endif // !__MY_PHONEINFO_CLASS_H__
//---------------------------------------------------------------------------------------
// HAS -A
#ifndef __MY_INFO_CLASS_H__
#define __MY_INFO_CLASS_H__
class MyInfo
{
public:
MyInfo();
MyInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
private:
MyPhoneInfo m_Phone;
};
#endif // !__MY_INFO_CLASS_H__
//---------------------------------------------------------------------------------------
// IS -A
#ifndef __MY_INFO_CLASS_H__
#define __MY_INFO_CLASS_H__
class MyInfo: private MyPhoneInfo
{
public:
MyInfo();
MyInfo(int _nCount, const std::string& _ssName, const std::string& _ssPhone );
virtual ~MyInfo();
};
#endif // !__MY_INFO_CLASS_H__
- 기본생성자의 사용 유무까지 판단하여 작성한다.
- 소멸자의 Virtual 키워드는 상속을 허용한 CLASS만 작성한다. 해당 키워드로 상속 가능 여부를 판단한다.
- 상속은 public, private, protected를 구별해서 작성한다. 무지성 public 상속 금지
-
728x90