468,537 Members | 1,977 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

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 1817
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Ellarco | last post: by
19 posts views Thread by Capstar | last post: by
2 posts views Thread by jashugun | last post: by
18 posts views Thread by chankl | last post: by
4 posts views Thread by Paulo Matos | last post: by
27 posts views Thread by Nate Eldredge | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.