Opaque pointers, templates and ABCs

  • Thread starter =?iso-8859-1?q?Ernesto_Basc=F3n?=
  • Start date
?

=?iso-8859-1?q?Ernesto_Basc=F3n?=

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
 
R

Roland Pibinger

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
 
?

=?iso-8859-1?q?Ernesto_Basc=F3n?=

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?
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?
 
R

Roland Pibinger

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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top