Thread: free functions (or static members) to access private function from different class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    free functions (or static members) to access private function from different class

    Here's my scenario ...

    I have two classes class A & B

    Code:
    // A.h
    
    Class A
    {
    private:
           void nicefoo();
           void badfoo();
    }
    Code:
    //B.H
    
    Class B
    {
    public : 
        static void firstFreeFoo();
        static void secondFreeFoo();
    }
    
    void B::firstFreeFoo()
    {
       A.niceFoo(); // I need to call nicefoo ?
    }
    
    
    void B::secondFreeFoo()
    {
       A.badFoo(); // I need to call badfoo ?
    }
    How do i achieve this...?

    my thoughts...
    1. Perhaps i can declare an instance of A inside both static functions, but then both nice&bad foo are private
    2. If i do declare two instance of foo, then i have too many class A instances, what if there are many static functions to use A? Isn't it a problem to have too many instances.
    3. Should A be a singleton?
    Last edited by csonx_p; 07-25-2008 at 04:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 20
    Last Post: 01-26-2009, 01:33 AM
  2. How properly inherit from template?
    By 6tr6tr in forum C++ Programming
    Replies: 118
    Last Post: 04-25-2008, 04:30 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Private Static class members
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2005, 06:37 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM