구조체 인 정적 멤버를 갖고 싶은 클래스가 있습니다.구조체 인 정적 클래스 멤버
예를 들어: .H 파일 :
typedef struct _TransactionLog
{
string Reference;
vector<int> CreditLog;
int id;
}TransactionLog;
class CTransactionLog {
static TransactionLog logInfo;
public:
static void Clear();
static TransactionLog getLog();
};
.cpp 파일 :
void CTransactionLog::Clear()
{
logInfo.Reference = "";
logInfo.CreditLog.clear();
logInfo.id = 0;
}
TransactionLog CTransactionLog::getLog()
{
return logInfo;
}
내가
설명 리소스 경로 위치 유형
정의되지 않은 참조를 얻을 `CTransactionLog :: lo gInfo 'TransactionLog.cpp
누군가이 작품을 만드는 방법을 보여줄 수 있습니까? 정적 멤버가 struct (stl 멤버로) 인 경우 정적 멤버 메서드를 사용하여이 멤버를 조작하고이 헤더를 코드의 다른 일부에 포함합니다. 이것은 응용 프로그램을 통해 로깅을 추가하는 데 사용해야합니다.
,하지만 당신은 _TransactionLog' '와 같은 예약 된 이름을 사용하면 안됩니다. 또한 C++에서 typedef를 사용할 필요가 없습니다. 클래스 이름은'struct' 또는'class'로 정규화하지 않고 직접 사용할 수 있습니다. –
가능한 [정의되지 않은 참조/확인할 수없는 외부 기호 오류 란 무엇이며 어떻게 수정합니까?] (http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external- symbol-error-and-do-do-i-fix) –