Private Class Functions

This is a discussion on Private Class Functions within the C++ Programming forums, part of the General Programming Boards category; Hello Everyone! I was wondering if someone could tell me how or refer me to a good place to find ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    11

    Question Private Class Functions

    Hello Everyone!
    I was wondering if someone could tell me how or refer me to a good place to find out how to call a private class function in a class's public member function.

    This is how I did it:
    Code:
    void ATM::deposit(string ptrans, string pacct, int pmoney)
    {
            cout <<"It is working" << endl;
                    if(pacct == "Checking Account")
                            checkBal = checkBal + pmoney;
             
                    else if(pacct == "Savings Account")
                            saveBal = saveBal + pmoney;
             
                    void printRe(string ptrans, string pacct, int pmoney);
            
    }//end deposit function
    However when it gets to the printRe function call, it does not work.
    Any ideas? I tried doing different kinds of function calls like the one you may use when calling a class function from a client program.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Does that even compile?

    You call a private function like any other function. Say ATM::printRe is the private function, and ATM::deposit is the public function, then just:
    Code:
    void ATM::deposit(string ptrans, string pacct, int money)
    {
        // ...
        printRe(ptrans, pacct, pmoney);
    }
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    11
    I see, but when I try it that way I received an error that said:

    atm.cpp: In member function 'void ATM::deposit(std::string, std::string, int)':
    atm.cpp:47: error: expected primary-expression before 'ptrans'
    atm.cpp:47: error: expected primary-expression before 'pacct'
    atm.cpp:47: error: expected primary-expression before 'int'

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    Post the code you're using.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    11
    OOOOHHHHH OOoops!!!!! Ok I see I see ^_^.
    Thanks you soooooo much!!!
    I was making stupid little mistakes.

    THanks ^_-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions in class and class variables.
    By Karakus in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2006, 02:29 AM
  2. Can't Access the private member from base class
    By planet_abhi in forum C# Programming
    Replies: 3
    Last Post: 01-09-2006, 03:30 AM
  3. Private Static class members
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2005, 06:37 AM
  4. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21