473,372 Members | 1,101 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

private static function

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.
hello, If you remember me from yesterday, having some problems. 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:

Expand|Select|Wrap|Line Numbers
  1. private:
  2.     static void logger(string message, string outputFileName="")
  3. {
  5.         Logger& loggerInstance = Logger::getInstance();
  6.         if(outputFileName != "")
  7.         {
  8.             loggerInstance.initialize(outputFileName);
  9.         }
  10.         else
  11.         {
  12.             loggerInstance.addMsg(message);
  13.         }
  14. }
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:

Expand|Select|Wrap|Line Numbers
  1.     static void initialize(string outputFileName)
  2.     {
  3.         logger("",outputFileName);
  4.     }
  5.     static void addMsg(string message)
  6.     {
  7.         logger(message);
  8.     }
So I don't want the user to use a the logger in a potentially wrong way.

Feb 27 '09 #1
1 6811
1,764 Expert 1GB
Simply put,you do not need that function at all.You can write initialize() like a first part of the logger function and addMsg() as the else case.Or if you want you can make a class which will wrap around logger adding another layer of indirection and than put that class as a static member:

Expand|Select|Wrap|Line Numbers
  1. class LogWrapper
  2. {
  3. private:
  4.    void logger(string msg,string file="")
  5.    {
  6.          //Implementation
  7.    }
  9. friend class helperFunctions; //logger is private method,only friends can access            
  10.                                           //them.
  11. };
  14. //Your helperFunctions class(or however do you call it) 
  15. private:
  16.    Logwrapper wrapper;
  18. };
  20.     static void initialize(string outputFileName)
  21.     {
  22.         wrapper.logger("",outputFileName);
  23.     }
  24.     static void addMsg(string message)
  25.     {
  26.         wrapper.logger(message);
  27.     }

It's your call,but I would opt for the first one.
Feb 28 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Andy | last post by:
1) Is there any use of defining a class with a single constructor declared in private scope? I am not asking a about private copy constructors to always force pass/return by reference. 2) Is...
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always...
by: baumann | last post by:
hi all, according the private / protected access control, - private; that is, its name can be used only by members and friends of the class in which it is declared. - protected; that is,...
by: Andrew Poulos | last post by:
I having some trouble understanding how to make functions private I have created an instance of an object using a constructor function and there are 4 prototypes: Comm = function() { //blah...
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
by: VSP | last post by:
Hello, I am just implementing singleton pattern in various ways. In one implementation I created a static member and returning that static member in the getInstance() function. I have made...
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
by: Stodge | last post by:
I've exposed a C++ class to Python using Boost Python. The class, let's say it's called Entity, contains private static data, which is an array of strings. Though I think it implements it using...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.