我有一個class
在C++中調用Tracer
。在我Tracer.h
文件我有:const void *對象初始化問題C++
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
是Tracer.h
中m_theObject
的聲明Tracer.cpp:27
是m_theObject(theObject
系列。 在我的彙編級別,警告被視爲錯誤。爲什麼編譯器會抱怨const void *
指針的初始化?
在初始化程序列表中交換'm_lineNum(line)'和'm_theObject(theObject)'。 – Joe 2012-08-01 12:47:58