468,484 Members | 1,751 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

Accessing private functions

34
I have been given the class definition below:

Expand|Select|Wrap|Line Numbers
  1. class llist
  2. {
  3. private:
  4.     record *start;
  5.     char filename[16];
  6.     int readfile();
  7.     int writefile();
  8.     record * reverse(record *);
  9.     void cleanup();
  10.  
  11. public:
  12.     llist( );
  13.     llist(char []);
  14.     ~llist( );
  15.     int addRecord(char[], char[], int, char[]);
  16.     int printRecord(char [ ]);
  17.     int modifyRecord(char[], char[], char[]);
  18.     void printAll();
  19.     int deleteRecord(char []);
  20.     void reverse();
  21. };
From what I know, the only way I can access private members is to create accessor methods for the member variables and use friend for the functions. However, since instructions were given not to make any changes to the class definition, how can I access them?

I thought about calling the readfile() and writefile() functions in the constructor and destructor. But then shouldn't they only be used to initialize member variables and deallocate them?

Regards,
Jthep
Dec 4 '07 #1
3 3402
weaknessforcats
9,207 Expert Mod 8TB
The public functions constitute the class interface. If you are not allowed to chnage the class declaration, then you can't add accessor functions or friend functions. (And, by the way, this not the situation where you use a friend).

Is this some kind of class exercise to hear the sound of one hand clapping??
Dec 4 '07 #2
jthep
34
Yes, we're not allowed to change the class definition without consulting. That's why I called the private function read and write in the constructor, destructor respectively.
Dec 4 '07 #3
weaknessforcats
9,207 Expert Mod 8TB
Only the class member functions can call private class member functions. The purpose of the private member function sus usually to provide support to the other member functions.

So, I guess, you are doing what you are supposed to do.
Dec 4 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Sandeep | last post: by
4 posts views Thread by ambar.shome | last post: by
6 posts views Thread by harry | last post: by
6 posts views Thread by David Hearn | last post: by
29 posts views Thread by RageARC | last post: by
2 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.