Thread: help in classes

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    help in classes

    Hi.
    I am stuck in the following problem and I am hoping that if anyone can help me in this.
    So imagine a class..


    Code:
    Class myClass{
    func1(params );
    func2(params);
    private:
    ---state vars--
    }
    Now.. lets say in definitations, I want to use the func2 definition in func1..
    how do i use it?
    Code:
    myClass::func1()
    {
    
    //needs to call func2() here..
    
    }
    It would nice if anyone can guide me in this..
    Thanks a lot for help and suggestion.
    best regards

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Since both functions are part of the same class you would call it just like a global function.
    Code:
    myClass::func1()
    {
        funct2();   // call func2() here..
    
    }
    Jim

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    In the position you've written it..The ""---state vars--"" would already be private...
    and in
    Code:
    //needs to call func2() here..
    I've recently heard that
    Code:
    this->func2(..params..);
    is a better practice than;
    Code:
    func2(..params..);
    Is it true...if yes..why?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    In my opinion I don't think it is a better practice, to me it just adds clutter to the function.

    Jim
    Last edited by jimblumberg; 05-10-2011 at 07:13 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversions between base classes and derived classes
    By tharnier in forum C++ Programming
    Replies: 14
    Last Post: 03-18-2011, 10:50 AM
  2. Classes access other classes local variables
    By parad0x13 in forum C++ Programming
    Replies: 6
    Last Post: 01-14-2010, 04:36 AM
  3. Classes with Other Classes as Member Data
    By njd in forum C++ Programming
    Replies: 2
    Last Post: 09-27-2005, 09:30 AM
  4. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 02:46 PM
  5. Classes inside Classes
    By LostGeneration in forum C++ Programming
    Replies: 7
    Last Post: 11-16-2003, 12:02 PM