473,698 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ interface

Is there a way in C++ to create a "true" interface. I want to create
an absract class that other classes can inherit from and be forced to
implement the interface's abstract (pure virtual) methods. However, it
has to be a true interface in that it doesn't add any overhead (when
the derived object is created) with the interface's constructors and
destructor because they don't exist for the interface. Does that make
sense? I just want an interface, not all the OOP stuff like
constructors, destructor and etc. In other words, I don't want the
interface's (system default or user defined) constructors & destructor
to be called.
Jul 22 '05
10 4467
"Ron Natalie" <ro*@sensor.com > wrote in message
news:3f******** *************** @news.newshosti ng.com...

"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message news:zl******** ***********@twi ster.nyroc.rr.c om...
I don't understand your example. If GetMeSomeThingT hatSupportsInte rface uses operator new() to create an instance of something derived from Interface
then how does it get deleted?
Through some interface call or some external scheme. An example is the

Microsoft COM objects. The IUnkown interface provides reference counting that manages when the object actually needs to committ suicide. You don't delete stuff through interfaces in general.
Actually, I DO delete things through interfaces! There is an advantage to
it. For instance with COM there is a reference counting mechanism built into
every COM object as you say. But a reference counted smart pointer abstracts
a similar mechanism and keeps it separate from the object itself. This
allows me to write a whole library of polymorphic objects without even
considering reference counting or memory management. All I need to do is
provide a do-nothing virtual destructor in all interfaces.
I can't delete it myself without dynamic casting to a type which has a destructor.

Nothing can prevent people being stupid with dynamic cast.
I disagree that deleting an object polymorphically is a bad idea. In
fact making the destructor protected prevents me from using it with smart
pointers.


Nothing precludes that,


Nothing precludes what? A reference counted smart pointer deletes the object
through the pointer when the smart pointer is destroyed. Hence if the object
cannot be deleted this way the code will not compile.
and it defeats the interface paradigm if you actually
think the interface IS the object. The interface is just a set of manipulations of the object. Not all interfaces are BASE CLASSES. Some are mixins.


An interface with a virtual destructor can be used as a base class or added
later as a "mixin". For instance, in

http://home.rochester.rr.com/cyhome/uvs/samp.html

uvs::IDiDist (an interface to a discrete distribution) is used as a base
class for various discrete distributions but is added to uvs::DiSummary
("mixed in") at the point where we define histogram uvs::DiHistogra m. That
just models the fact that a histogram is a distribution and a sample
statistic both.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #11

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

Similar topics

4
8193
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by making my contnent dlls implement an interface created in vb6. The viewer application is bound to this interface. This way, I am able to add Content without redeploying the dlls (I just have to add the new dlls). I want to write new content for...
9
4642
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
4
2579
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two last methods (for space I modified method names in my example below). I added those. Everything but the two new methods I added referenced the ISSEAssemblyCom interface below. I was told I would need to create a secondary interface...
3
4138
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
6
3011
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
4255
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the interface and accessing the datastore MUST pass in a UserToken in the constructor of the object. Is this not possible? Am I forced to add the UserToken as a property on the object instead? /Ole
2
4985
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators "," variable-declarator variable-declarator:
0
2506
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
15
2788
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
8
2080
by: rn5a | last post by:
Suppose I have the following class code: Imports System Imports System.Data Imports System.Data.SqlClient Public Class DBSettings Private sqlCmd As SqlCommand Private sqlConn As SqlConnection Public ConnectionString As String
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7732
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.