What is the common way/design-pattern (if any) in C++ for delegating
function calls that are not handled by a certain class. Public
inheritance would be one way but not all classes are meant to inherit
from (e.g. STL).
Example:
class A
{
public:
foo();
private:
set<stringmyset ;
}
A myObj;
myObj.insert(); // compiler error of course
Is there some mechanism (direct or indirect) where a function that is
not handled by myObj gets delegated to another object (e.g. myset)?
Jun 27 '08
13 1471
tedzhou <zh*******@163. comwrote:
On May 24, 5:19*pm, Ian Collins <ian-n...@hotmail.co mwrote:
James Kanze wrote:
On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.co mwrote:
* * [...]
I was going to suggest that technique, but decided against it
as the OP wanted to delegate members of std::set. *I wouldn't
recommend deriving from a standard container.
Not even privately? *I have no problems with private
inheritance from a standard container; private inheritance is
part of the implementation.
Yes, you're right, I overlooked private inheritance.
Private inheritance is not suggested on standard container either.
Because the standard containers are not designed for inheritance at
all. Just think about the polymorphism and virtual destruction,
then you'll get the conclusion that inheritance from standard
containors will be dangerous.
Polymorphism and virtual destruction don't apply to private
inheritance.
tedzhou wrote:
On May 24, 5:19 pm, Ian Collins <ian-n...@hotmail.co mwrote:
>James Kanze wrote:
>>On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.co mwrote: [...] I was going to suggest that technique, but decided against it as the OP wanted to delegate members of std::set. I wouldn't recommend deriving from a standard container. Not even privately? I have no problems with private inheritance from a standard container; private inheritance is part of the implementatio n.
Yes, you're right, I overlooked private inheritance.
Private inheritance is not suggested on standard container either.
Because the standard containers are not designed for inheritance at
all.
Not necessarily. Several of the standard adapter classes
(std::priority_ queue for example) have protected members, which implies
that they were designed to be inherited from.
tedzhou wrote:
On May 24, 5:19*pm, Ian Collins <ian-n...@hotmail.co mwrote:
>James Kanze wrote:
On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.co mwrote:
[...] I was going to suggest that technique, but decided against it as the OP wanted to delegate members of std::set. *I wouldn't recommend deriving from a standard container.
Not even privately? *I have no problems with private inheritance
from a standard container; private inheritance is part of the
implementation.
Yes, you're right, I overlooked private inheritance.
Private inheritance is not suggested on standard container either.
Because the standard containers are not designed for inheritance at
all.
Just think about the polymorphism and virtual destruction , then
you'll
get the conclusion that inheritance from standard containors will be
dangerous.
That argument is bogus for two reasons:
(a) As others have pointed out, private differs from public inheritance with
regard to destruction.
(b) Even with public inheritance, the argument does not hold as it would
apply equally well to std::unary_func tion or std::iterator, two classes
that are meant to be publicly inherited from and that lack virtual
destructors. Inheritance in C++ is not necessarily tied to polymorphism.
[Note: that you failed to point out a valid reason as to why public
inheritance from standard containers might not be such a good move, is not
to say that there are no such reasons. However, those tend to focus on
other issues rather than the lack of a virtual destructor.]
Best
Kai-Uwe Bux
On May 26, 11:00 am, Ian Collins <ian-n...@hotmail.co mwrote:
tedzhou wrote:
On May 24, 5:19 pm, Ian Collins <ian-n...@hotmail.co mwrote:
James Kanze wrote: On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.co mwrote: [...] I was going to suggest that technique, but decided against it as the OP wanted to delegate members of std::set. I wouldn't recommend deriving from a standard container. Not even privately? I have no problems with private inheritance from a standard container; private inheritance is part of the implementation .
Yes, you're right, I overlooked private inheritance.
Private inheritance is not suggested on standard container
either. Because the standard containers are not designed
for inheritance at all. Just think about the polymorphism
and virtual destruction , then you'll get the conclusion
that inheritance from standard containors will be dangerous.
With public inheritance maybe, but you can't point a base* to
a derived object if derived uses private inheritance.
You can, and in fact, one frequent use of private inheritance
involves doing just that. But you need cooperation from the
derived class to do so: if the derived class doesn't give you
the Base*, you can't get it otherwise. (The "frequent use" is
to derive privately from something like "EventHande r": for
normal client code, this is an implementation detail, and they
can't consider the class to be an EventHander. But the class
itself may register itself as an EventHander with some
EventNotifier, who will address the class through an
EventHander*.)
Private inheritance hides the fact that a derived is a base.
Except in the explicit cases where it wants to behave as a base.
None of which is really a problem when deriving privately from a
standard container, since you, the author of the class, have
total control, and of course, you will not expose the
derivation.
--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rene Pijlman |
last post by:
Section 6.5 "What is delegation?" of the FAQ says:
"Python programmers can easily implement delegation. For example, the
following class implements a class that behaves like a file but converts
all written data to uppercase:
class UpperOut:
def __init__(self, outfile):
self.__outfile = outfile
def write(self, s):
|
by: DPfan |
last post by:
Is the following so-called "delegation"? If not how to make some changes so
that the F class delegates its operation to an E instance.
On the other hand the following code runs without any problem. Is there any
potential problems with it?
class E
{
public:
void Draw_E(int a, int b) { cout << "Draw in E " << a*b<< endl; }
|
by: Tony Johansson |
last post by:
Hello!
What does it mean with delegation and can you give me one example.
//Tony
|
by: Preston Park |
last post by:
We are trying to get windows authentication to work with Reporting Services
and Analysis Services in a way that may be unsupported.
Setup:
There are two domains: A and B.
There are two servers in the A domain: A\R and A\S
Server R is running Reporting Services to serve OLAP reports from data on
|
by: russell.lane |
last post by:
I'm building out a pretty standard n-tier web application. The stack
includes application/presentation, biz logic, and data access layers on top
of an SQL server back end.
We want to use impersonation and delegation to forward the user's Windows
login through all layers in the stack. To support this, I'm setting up a
set of domain accounts which we use to create SPNs for the various services
in the various layers.
At this point, I'm...
| |
by: JimLad |
last post by:
In advance, sorry if this is the wrong group...
SQL Server 2000 SP3 on Server 2003. SQL Account and Computer both
Trusted for Delegation. Given SPN.
IIS 5.0 on W2000. Kerberos enabled. Computer Trusted for Delegation.
Integrated Windows Authentication selected. Medium pooled. Not the
default website - using IP address to connect from client.
IWAN_<computernamelocal account is running as part of operating
system and trusted for...
|
by: Marc Castrechini |
last post by:
This is a classic double hop delegation issue, however its the first time we
are setting this up so we are doing something incorrectly. If we run
through the IDE or using a localhost path on the web server the command
succeeds. However, if we use the servername or ip through IIS it fails.
For this reason we know we have permissions setup correctly on the file
server.
Can anyone identify what we could possibly be doing wrong here:
...
|
by: Patrick |
last post by:
Hello
I have the following scenario
- SQL 2005 server (serversql)
- Windows 2003 with IIS (serveriis)
- Windows 2003 ADS (serverads)
I want to connect to an intranet application using NTML with impersonation
and delegation. so for this I made the following change in web.config
<identity impersonate="true"/>
|
by: =?Utf-8?B?TWF5ZXI=?= |
last post by:
Hi,
I'm using two form classes and I would like all methods of the second class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,
Mayer
|
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: 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...
|
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: 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...
| |