472,783 Members | 979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

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 3606
weaknessforcats
9,208 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,208 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

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

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
5
by: Sandeep | last post by:
Hi, In the following code, I wonder how a private member of the class is being accessed. The code compiles well in Visual Studio 6.0. class Sample { private: int x; public:
4
by: ambar.shome | last post by:
Hi, Please take a look at the code snippet given below:#include<iostream> using namespace std; class A { public: virtual void test(){cout<<"Default implementation called"<<endl;}
6
by: harry | last post by:
Hi ppl I have a question about memory layout of a class. Consider the code below: class Base1 { virtual void f() { cout << "Base1::f" << endl; } virtual void g() { cout << "Base1::g" <<...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
4
by: rognon | last post by:
Hi there, I'm trying to do something, but I don't know if it's possible. Basically, I want to have a public static class method that could access a private object's method. I would like to be able...
2
by: mickey22 | last post by:
Hi all, I have some data members and member functions that are declared as private in a class A. Now I want to use these data members and functions(which are private) in my new C++ source...
29
by: RageARC | last post by:
I have the following code: index.php: class main_class { public $database = new DAL; public $html = new HTML; }
6
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.