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

Opaque pointers, templates and ABCs

Hi everybody:

I have two questions:

1. I'm using opaque pointers in my classes to hide their data
structures; there is a way to use opaque pointers in template classes;
since the implementation and the declaration of the template class is
in the same file, the use of opaque pointers does not make sense,
but... what about implementation hiding for libraries? how can I make
sure that the new versions of my libraries have binary compatibility
with the old ones?

2. As a good C++ design, should be better using ABCs instead of opaque
pointers, providing just abstract interfaces to my users and change
arbitrarily the implementation if needed?

Regards,
Ernesto

Oct 25 '06 #1
3 2127
On 25 Oct 2006 10:17:38 -0700, "=?iso-8859-1?q?Ernesto_Basc=F3n?="
<eb******@gmail.comwrote:
>1. I'm using opaque pointers in my classes to hide their data
structures;
By 'opaque pointers' you mean pointers to forward declared classes
(not void*)?
>there is a way to use opaque pointers in template classes;
since the implementation and the declaration of the template class is
in the same file, the use of opaque pointers does not make sense,
but... what about implementation hiding for libraries? how can I make
sure that the new versions of my libraries have binary compatibility
with the old ones?
Your interface should be binary compatible as long as you
- don't use templates,
- don't change or add data members
- don't change function signatures (member and non-member)
- only add (not remove) non-member functions (adding virtual member
functions may not be binary compatible)
>2. As a good C++ design, should be better using ABCs instead of opaque
pointers, providing just abstract interfaces to my users and change
arbitrarily the implementation if needed?
It depends. Pure virtual base classes may be a solution. The best way
to ensure binary compatibility and information hiding is to provide a
C interface for your C++ library.

Best regards,
Roland Pibinger
Oct 25 '06 #2
By 'opaque pointers' you mean pointers to forward declared classes
(not void*)?
Right!

Your interface should be binary compatible as long as you
- don't use templates,
- don't change or add data members
- don't change function signatures (member and non-member)
- only add (not remove) non-member functions (adding virtual member
functions may not be binary compatible)
Do you mean non-virtual member functions?
2. As a good C++ design, should be better using ABCs instead of opaque
pointers, providing just abstract interfaces to my users and change
arbitrarily the implementation if needed?

It depends. Pure virtual base classes may be a solution. The best way
to ensure binary compatibility and information hiding is to provide a
C interface for your C++ library.
Should not be enough to provide object factories for my abstract
classes?
Best regards,
Roland Pibinger
Oct 25 '06 #3
On 25 Oct 2006 12:03:54 -0700, "=?iso-8859-1?q?Ernesto_Basc=F3n?="
wrote:
>Your interface should be binary compatible as long as you
- don't use templates,
- don't change or add data members
- don't change function signatures (member and non-member)
- only add (not remove) non-member functions (adding virtual member
functions may not be binary compatible)

Do you mean non-virtual member functions?
Virtual member functions may alter the vtable layout (and may
therefore not be binary compatible). Non-virtual member functions
should be ok.
>2. As a good C++ design, should be better using ABCs instead of opaque
pointers, providing just abstract interfaces to my users and change
arbitrarily the implementation if needed?

It depends. Pure virtual base classes may be a solution. The best way
to ensure binary compatibility and information hiding is to provide a
C interface for your C++ library.

Should not be enough to provide object factories for my abstract
classes?
It depends. Do you want to be 'binary compatible' or just 'interface
compatible'?

Best wishes,
Roland Pibinger
Oct 25 '06 #4

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

Similar topics

12
by: Ellarco | last post by:
``Opaque-pointer representing the ID of an object. struct _objID; typedef struct _objID * objectID;'' Hi again. Im using an api that defines an objectID type. The above represents the extent...
19
by: Capstar | last post by:
Hi NG, I've read some time ago in this NG, that when you're writing a library it can be good practice to use an opaque type to point to your structures if the user doesn't need to modify the...
2
by: Kurt Ng | last post by:
Hi, y'all. Can anyone help me on this problem? I'm working with a third-party C dll, and I'm having trouble importing into C# the dll's methods that return one of the dll's defined types,...
2
by: jashugun | last post by:
Hello to everybody, I'm trying to write a small program which is meant to interact with an sqlite database. My idea is to create once a database handler, which happens to be an opaque pointer (a...
18
by: chankl | last post by:
Can anyone explain what's an opaque pointer and how it's implemented in C? I read about this concept in the book "C interfaces and implementations". Here's an example from the book (list.h -...
4
by: Paulo Matos | last post by:
Hi all, C++ FAQ Lite points you out to ABCs to define interfaces in C++, however, in a well-defined big system which may consist of a huge number of interfaces, the use of ABCs may incur in a...
27
by: Nate Eldredge | last post by:
Consider the following pseudo-code: #include <opaque.h> struct foo { int a; opaque_t op; int b; };
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.