Thread: Passing private member into non class function

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    Passing private member into non class function

    Long story short, I need the recursive function recQS to sort the private member variable "list.items". Items is of vector<T> type. I simply cannot figure out how to do this without declaring recQS as a friend to UList. How can I pass it into recQS? I've been searching the boards for a couple of hours.
    Code:
    template <class Y>
    void sort(UList<Y>& list){
      recQS(list.items, 0, list.size()-1);
    }
    
    void recQS(_______, size_t first, size_t last){
    ...
    ...
    ...
    }
    Thanks for any help you might be able to offer!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    A little more code would probably help you get some kind of answer. Perhaps you could post the code for your class so we can see what type of variables you are actually working with.

    Jim

  3. #3
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by brunion1 View Post
    Long story short, I need the recursive function recQS to sort the private member variable "list.items". Items is of vector<T> type. I simply cannot figure out how to do this without declaring recQS as a friend to UList. How can I pass it into recQS? I've been searching the boards for a couple of hours.
    Code:
    template <class Y>
    void sort(UList<Y>& list){
      recQS(list.items, 0, list.size()-1);
    }
    
    void recQS(_______, size_t first, size_t last){
    ...
    ...
    ...
    }
    Thanks for any help you might be able to offer!
    recQS() shouldn't need to be declared a friend since it just takes a vector and two integers as arguments. But sort() no doubt needs to be (unless of course you just make it a member function, which wouldn't be such a bad idea)...

  4. #4
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Location
    Seattle, Washington
    Posts
    59
    Post some real code!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can Nested class access parent class's private member?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 08:42 AM
  2. Passing class member function to pthread_create
    By lehe in forum C++ Programming
    Replies: 6
    Last Post: 03-27-2009, 07:47 PM
  3. Replies: 9
    Last Post: 05-03-2007, 03:50 PM
  4. Function in a private member of a class?
    By RealityFusion in forum C++ Programming
    Replies: 9
    Last Post: 09-02-2005, 05:42 PM
  5. passing a class member function by reference?
    By m712 in forum C++ Programming
    Replies: 4
    Last Post: 12-08-2002, 05:01 AM