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. 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
"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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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.
|
by: Juan |
last post by:
Thanks,
Juan.
|
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...
|
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...
| |
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,
|
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})
|
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.
|
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...
|
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,...
|
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,...
| |
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |