private static function

Good day to all. I have some strange problem and checking if some one can help me.

I've defined a helpFunctions.cpp class with static functions. now I have a static function that I don't need the user to see so I'm trying to make it private.it works fine as public but once I put it in the private scope here is what I get:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private:
	static void logger(string message, string outputFileName="")
{

		Logger& loggerInstance = Logger::getInstance();
		if(outputFileName != "")
		{
			loggerInstance.initialize(outputFileName);
		}
		else
		{
			loggerInstance.addMsg(message);
		}
}


the error: ‘static void helpFunctions::logger(std::string, std::string)’ is private.

If it would help the logger instance that I'm using is a singleton instance.
The reason to put It private is because I have two functions:


1
2
3
4
5
6
7
8
	static void initialize(string outputFileName)
	{
		logger("",outputFileName);
	}
	static void addMsg(string message)
	{
		logger(message);
	}


So I don't want the user to use a the logger in a potentially wrong way.
To my knowledge there's nothing wrong with making static functions private. If you're getting a "this function is private" error then you must be trying to access it from outside the class.

The private function must be being called from somewhere outside the class. Check the line number for the error that the compiler is giving you to find where it is.
the function is in the class and the line number is:

static void logger(string message, string outputFileName="").

Whou, while looking over the code to answer you found my really stupid mistake.
Just to check, before I had the 2 functions in the second code box I used in the main the logger function and when I got it to be private I haven't erased the lines in the main.

so stupid, but at least found it.
Last edited on
Topic archived. No new replies allowed.