Thread: question about classes and functions

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    17

    question about classes and functions

    is their a way to call a class function within another class function?

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    A) Why not make the function global?

    B) Look up the friend declaration. I think it might help you.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    17
    but if its a class function, isnt it already global?

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Unless it is static, the only way it can be accessed is if a whateverclass example is declared. Such as:


    Code:
    class a
    {public:
       void func(){cout<<"a class function";};
    };
    
    
    int main()
    {a dog;//has to be declared to access func
     dog.func();
     return 0;
    }

  5. #5
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    If it's a derived Class, and you'd like to implicitly call the function of one of it's classes, check out the :: Operator

    ex.

    CLASS_X:ISPLAY();


    p.s.

    Friend Functions prove that your code isn't logically structured.

  6. #6
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    However that smiley face got there, it should be a 'D'

  7. #7
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    ::d

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Classes Question
    By kbro3 in forum C++ Programming
    Replies: 9
    Last Post: 08-14-2008, 07:43 AM
  2. Replies: 3
    Last Post: 11-04-2006, 01:09 PM
  3. Classes being able to use other classes functions
    By rainmanddw in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2006, 11:19 AM
  4. Headers, Classes, and Functions question.
    By Zeusbwr in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2004, 03:18 AM
  5. Another question on classes
    By hpy_gilmore8 in forum C++ Programming
    Replies: 26
    Last Post: 05-24-2003, 09:11 AM