473,624 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

optional interface

How do I write a class with "optional" interface like the following one:

class A
{
:
// inteface_a
// interface_b
};

void main()
{
A obj_a(interface _a); // define an object with interface a
A obj_b(interface _a | interface_b); // define an object with
interface a AND b

obj_b.func_b(); // calling function defined in interface
b; OK
obj_a.func_b(); // calling function not defined in
interface a; Compilation error
}

--

Can I write something like this in C++? Thanks.
Regards,
Milan.
Jul 19 '05 #1
3 2083
"Milan" <so*****@intern et.com> wrote...
How do I write a class with "optional" interface like the following one:

class A
{
:
// inteface_a
// interface_b
};

void main()
int main()
{
A obj_a(interface _a); // define an object with interface a
A obj_b(interface _a | interface_b); // define an object with
interface a AND b

obj_b.func_b(); // calling function defined in interface b; OK
obj_a.func_b(); // calling function not defined in
interface a; Compilation error
}

--

Can I write something like this in C++? Thanks.


By using templates, I suppose. Something like

template<class a, class b = a> class A : public a, public b
{
};

// partial specialisation
template<class a> class A<a,a> : public a
{
};

struct interface_a
{
void func_a();
};

struct interface_b
{
void func_b();
};

int main()
{
A<interface_a> a_a;
A<interface_a, interface_b> a_ab;
a_a.func_a(); // OK
a_a.func_b(); // error
a_ab.func_b(); // OK
}

Victor
Jul 19 '05 #2
"Milan" <so*****@intern et.com> wrote in message
news:bg******** *@imsp212.netvi gator.com...
How do I write a class with "optional" interface like the following one:

class A
{
:
// inteface_a
// interface_b
};

void main()
int main() according to the standard
{
A obj_a(interface _a); // define an object with interface a
A obj_b(interface _a | interface_b); // define an object with
interface a AND b

obj_b.func_b(); // calling function defined in interface
b; OK
obj_a.func_b(); // calling function not defined in
interface a; Compilation error
}

--

Can I write something like this in C++? Thanks.
Regards,
Milan.


Inheritance looks suitable.

class A
{
public:
void func_a();
virtual ~A();
};

class B : public A
{
public:
void func_b();
};

A obj_a;
B obj_b;

obj_a.func_b(); // illegal
obj_b.func_b();
obj_b.func_a(); // legal

--
ES Kim

Jul 19 '05 #3
"Milan" <so*****@intern et.com> wrote in message news:<bg******* **@imsp212.netv igator.com>...
[how do I? question]

Sure, use inheritance. Put the stuff that is common to all
types in the base. Put the specialized stuff in different
child types.

For extra credit, look up public, private, and protected
inheritance.
Socks
Jul 19 '05 #4

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

Similar topics

0
1458
by: Philip Rittenhouse | last post by:
I have discovered a couple of problems with the way the universal gateway code handles optional parameters and variable argument lists in COM servers. It appears to only be a problem when you use the custom interface. What I found was that variable argument lists are not detected at all. Instead they are just converted from SAFEARRAYs to a Python list.
3
1245
by: John Roth | last post by:
Guido has posted a second blog entry on the optional static typing initiative. I like this a lot better than the first. http://www.artima.com/weblogs/viewpost.jsp?thread=86641 Now, the base objective seems to be to incorporate PyChecker functionality into the root. This in turn requires type inference, which in turn strongly suggests type annotations to help the inferencer out over rough spots.
8
2142
by: Alan J. Flavell | last post by:
What I was trying to do: to offer a default stylesheet, plus another small stylesheet which can be applied additionally to the default one. Preferably, the optional stylesheet should be initially in effect, but the user should be able to turn it off. My reading of the HTML4 spec (which is where this seems to be documented, though I reckon it's on-topic for this group): it seems to me that what I want, in the terms described there, is...
0
1123
by: Stephan Zaubzer | last post by:
Hi How can I develop a .net application which has optional features? There are many products out there, which give you the option of installing certain features when installing the software. How can I make certain features of my application optional (i.e. that you can choose whether to install them, but the application also works if they are not installed, but the feature is simply not accessible in the latter case). I don't want to...
6
1751
by: Christian Convey | last post by:
Hi guys, I'm looking at developing a somewhat complex system, and I think some static typing will help me keep limit my confusion. I.e.: http://www.artima.com/weblogs/viewpost.jsp?thread=87182 Does anyone know if/when that feature may become part of Python? Thanks very much,
3
7230
by: Ryan | last post by:
The code below gives me an error of "expression expected" at the first curly brace. Thanks for any help. Public Sub PopulateForm(Optional ByVal myID As Integer = -1, Optional ByVal myRecipients() As Integer = {-1})
12
2661
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be avoided. I'd like to hear your various opinions on this matter.
2
2014
by: Steve | last post by:
Kind of a strange question... I have a VB.NET 2.0 solution containing a main project (my EXE) and a number of other projects (class DLLs) that are "plug-ins" to the main app. These plugins get installed depending on each user's requirements. I'd like to implement a function in one plugin that only executes if another plugin is present. Typically, for one plugin to access a second plugin, I need to set a reference at design-time to the...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8348
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
8493
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
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 project—planning, coding, testing, and deployment—without 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...
0
5570
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
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2613
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
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1493
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.