我在 C++ 中有一个class
调用。Tracer
在我的Tracer.h
文件中,我有:
class Tracer{
public:
// not useful to the question.
private:
Logger *m_logger;
const char *m_who;
const char *m_fileName;
const void * m_theObject;
int m_lineNum;
int m_log_level;
}
在Tracer.cpp
我有:
Tracer::Tracer(
Logger *logger,
const void *theObject,
const char *who,
const char *file,
int line,
int log_level
) :
m_logger(logger),
m_who(who),
m_fileName(file),
m_lineNum(line),
m_theObject(theObject),
m_log_level(log_level)
{
// more implementation which is not useful to the problem.
问题是,当我初始化时m_theObject(theObject)
,我收到以下警告:
/home/pribeiro/workspace/Tracer.h:80: warning: 'const void* Tracer::m_theObject'
/home/pribeiro/workspace/Tracer.cpp:27: warning: when initialized here
Tracer.h:80
是中的声明m_theObject
并且Tracer.h
是Tracer.cpp:27
行m_theObject(theObject
。在我的编译级别中,警告被视为错误。为什么编译器抱怨const void *
指针的初始化?