473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3656
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.