Cannot access private member in singleton class destructor

前端 未结 5 936
感动是毒
感动是毒 2020-12-21 05:24

I\'m trying to implement this singleton class. But I encountered this error:

\'Singleton::~Singleton\': cannot access private member declared in class \'Singleton\'

5条回答
  •  遥遥无期
    2020-12-21 05:51

    The code you posted looks doesn't have any problem, so the problem must be in some other part of your source code.

    The error message will be preceded by the filename and line number where the problem is occurring. Please look at the line and you'll see a bit of code that is either trying to call delete on a singleton pointer or is trying to construct an instance of singleton.

    The error message will look something like this (the file and line number are just an example):

    c:\path\to\file.cpp(41) : error C2248: 'Singleton::~Singleton': cannot access private member declared in class 'Singleton'
    

    So in that case, you would want to see what is happening at line 41 in file.cpp.

提交回复
热议问题