473,394 Members | 1,797 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,394 software developers and data experts.

How do I use two different class interfaces to the same underlying data?

I've got a data class.
There is one point in the program I'm writing that needs access to the
non const functions of this class.
The rest of the program only needs the getters.
Currently I've solved this by handing out const pointers to this data
class to be used by the rest of the program.

But I don't like showing the non const functions to parts of the
program that just don't need them.
So I basically want two interfaces to the same underlying data.
One that allows reads and one that allows reads & writes.

Is this possible at all? If so where can I find an example/tutorial on
the net about it or in what book about C++ is this described?

P.s. while writing this I got an idea about a possible solution using
a base class with only the getters and a derived class that contains
the rest.
Jul 22 '05 #1
2 1063
velthuijsen wrote:
I've got a data class.
There is one point in the program I'm writing that needs access to the
non const functions of this class.
The rest of the program only needs the getters.
Currently I've solved this by handing out const pointers to this data
class to be used by the rest of the program.

But I don't like showing the non const functions to parts of the
program that just don't need them.
So I basically want two interfaces to the same underlying data.
One that allows reads and one that allows reads & writes.

Is this possible at all? If so where can I find an example/tutorial on
the net about it or in what book about C++ is this described?
I'd try "Advanced C++: Programming styles and idioms" by James Coplien.
P.s. while writing this I got an idea about a possible solution using
a base class with only the getters and a derived class that contains
the rest.


That's exactly what I was going to suggest.

V
Jul 22 '05 #2
> That's exactly what I was going to suggest.

V


Thank you for the confirmation that the idea is a good one.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan Tsafrir | last post by:
is the following code standard? (cleanly compiles under g++-4.0.2): struct Asc { bool operator()(int a, int b) {return a < b;} }; struct Des { bool operator()(int a, int b) {return b > a;} };...
2
by: Martin Zenkel | last post by:
Dear VS Team, using the Beta 2 of VS 2005 I've encontered the following problem. Let's assume threre are three Dll's, one unmanaged and two managed. In the unmanaged we put a simple unmanged...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
0
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
15
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
4
by: cantatahost | last post by:
Hello, Likely this has been asked before... We have a library (in DLL form) that we distribute. The interface to the library is all C, but within the library it uses C++ in many places. ...
3
by: Bob S | last post by:
A class in assembly A implements a COM interface as follows : internal interface IMyInterface { int MyMethod(); } class MyClass : IMyInterface
4
by: rach | last post by:
I just started to learn C++. I copied the following code from a data structure textbook to a ".h" file and couldn't compile it. The code contains three template interfaces. One inherits another. The...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.