Study/C++

[C++] Error C3861 - 'NULL': 식별자를 찾을 수 없습니다.

한돌이 2020. 3. 18. 14:58
#pragma once

template <typename T>
class Singleton
{
private:
	static T* m_pThis;

protected:
	Singleton()
	{

	};
	virtual ~Singleton()
	{

	};

public:
	static T* GetInstance()
	{
		if (m_pThis == NULL)
		{
			m_pThis = new T;
		}

		return m_pThis;
	}

	static void DestroyInstace()
	{
		if (m_pThis)
		{
			delete m_pThis;
			m_pThis = NULL;
		}
	}
};

template <typename T> T* Singleton<T>::m_pThis = 0;

<Singleton.h>


1. 오류

 싱글턴에 사용하기 위한 헤더를 만들 때 NULL을 체크하는 부분에서 NULL 식별자를 찾을 수 없다고 오류를 발생시킨다.

 

2. 해결 방법

 'stddef.h' 헤더 파일을 추가하면 된다.

 NULL은 실제로 C나 C++ 언어의 일부가 아니이며 stddef.h에서 0으로 정의가 되어 있기 때문이다.

 


참고 : https://stackoverflow.com/questions/15549873/set-head-to-null-null-undeclared-identifier