Hi,
I would extend class only a bit. In example: I want to write my own class,
that works all like std::string, only it also have member int mDatabase;
and it have method SaveToDatabase( );
I could do like:
class cStorableStr : std::string {
private:
int mDatabase;
public:
std::string::op erator=;
void SaveToDatabase( );
};
that inherits all methods from std::string, and operator(s) =.
But what if I would like to just unherit ALL. ALL operators, or ALL
members+operato rs. Is there a syntax allowing that?
Like:
public: std::string::*;
If not, perhaps it would be nice to have it?
--
Rafa³ Maj 6 2023
Raf256 wrote: Hi, I would extend class only a bit. In example: I want to write my own class, that works all like std::string, only it also have member int mDatabase; and it have method SaveToDatabase( );
I could do like:
class cStorableStr : std::string { private: int mDatabase; public: std::string::op erator=;
void SaveToDatabase( ); };
that inherits all methods from std::string, and operator(s) =.
But what if I would like to just unherit ALL. ALL operators, or ALL members+operato rs. Is there a syntax allowing that?
Like: public: std::string::*;
If not, perhaps it would be nice to have it?
Hi,
If you design it like the following, then don't you inherit everything
than can be inherited, plus the extra member and member method?
class cStorableStr: public std::string
{
private:
int mDatabase;
public:
void SaveToDatabase( );
};
Regards,
Peter Jansson
Peter Jansson <5e************ *******@newsb.t elia.net> Sunday 18 of December
2005 19:52 If you design it like the following, then don't you inherit everything than can be inherited, plus the extra member and member method?
class cStorableStr: public std::string { private: int mDatabase; public: void SaveToDatabase( ); };
But that do not inherit the operators.
Btw, in example above I forget "using", it should go:
class cStorableStr: public std::string
{
private:
int mDatabase;
public:
using std::string=; // <--------
void SaveToDatabase( );
};
--
Rafa³ Maj
Peter Jansson <5e************ *******@newsb.t elia.net> Sunday 18 of December
2005 19:52 If you design it like the following, then don't you inherit everything than can be inherited, plus the extra member and member method?
class cStorableStr: public std::string { private: int mDatabase; public: void SaveToDatabase( ); };
But that do not inherit the operators.
Btw, in example above I forget "using", it should go:
class cStorableStr: public std::string
{
private:
int mDatabase;
public:
using std::string::op erator=; // <--------
void SaveToDatabase( );
};
--
Rafa³ Maj
On Sun, 18 Dec 2005 19:26:04 +0100, Raf256 <sp**@raf256.co m.invalid>
wrote: Hi, I would extend class only a bit. In example: I want to write my own class, that works all like std::string, only it also have member int mDatabase; and it have method SaveToDatabase( );
I could do like:
class cStorableStr : std::string { private: int mDatabase; public: std::string::op erator=;
void SaveToDatabase( ); };
that inherits all methods from std::string, and operator(s) =.
But what if I would like to just unherit ALL. ALL operators, or ALL members+operat ors. Is there a syntax allowing that?
Like: public: std::string::*;
If not, perhaps it would be nice to have it?
You should inherit publicly from string, and then write the
non-inheritable member functions: default constructor, copy
constructor and copy assignment, and supply the assignment of string
and constructor from string:
class cStorableStr : std::string {
private:
int mDatabase;
public:
enum {default_mDatab ase=;}0;
cStorableStr(): mDatabase(defau lt_mDatabase) {}
cStorableStr(co nst cStorableStr& other)
:std::string(ot her),mDatabase( other.mDatabase ) {}
cStorableStr& operator=(const cStorableStr& other)
{std::string::o perator=(other) ;mDatabase=othe r.mDatabase;}
cStorableStr& operator=(const std::stringr& other)
{std::string::o perator=(other) ;mDatabase=defa ult_mDatabase;}
void SaveToDatabase( );
};
Be careful when using this class, as std::basic_stri ng does not have a
virtual destructor.
Regards
-- Zara
On 2005-12-18, Raf256 <sp**@raf256.co m.invalid> wrote: Hi, I would extend class only a bit. In example: I want to write my own class, that works all like std::string, only it also have member int mDatabase; and it have method SaveToDatabase( );
I could do like:
class cStorableStr : std::string { private: int mDatabase; public: std::string::op erator=;
void SaveToDatabase( ); };
that inherits all methods from std::string, and operator(s) =.
But what if I would like to just unherit ALL. ALL operators, or ALL members+operato rs. Is there a syntax allowing that?
Unfortunately, no.
In general, the variant of OOP that C++ supports requires design
of class hierarchies from base classes on up. You cannot usually
take an arbitrary class, which wasn't intended to be a base
class, and extend it using inheritance.
Like: public: std::string::*;
If not, perhaps it would be nice to have it?
You need to use aggregation, not public inheritance. Then provide
inline functions that forward to the contained object. This
provides exactly what you're asking for, though not a convenient
short-hand for it.
--
Neil Cerutti
On 2005-12-19, Neil Cerutti <le*******@emai l.com> wrote: You need to use aggregation, not public inheritance. Then provide inline functions that forward to the contained object. This provides exactly what you're asking for, though not a convenient short-hand for it.
One other option is to provide functions that operate on
std::strings to provide the extra functionality you need.
--
Neil Cerutti This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: greg |
last post by:
Discussion is invited on the following proto-PEP.
-------------------------------------------------------------
PEP ??? - Overloadable Boolean Operators
========================================
SUMMARY
This PEP proposes an extension to permit objects to define their own
|
by: JKop |
last post by:
First attempt:
class Blah : public int
{
};
So I began working on the next best thing:
|
by: Steve Summit |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
It's often explained that the reason for some of the imprecision
in C's definition is so that C can be implemented on different
kinds of machines -- say, those with 2's complement,
1's complement, or sign-magnitude arithmetic. But the followup
remark is sometimes also made that the choice of arithmetic isn't
completely unconstrained, since the bitwise operators seem to
presume a base-2 machine.
|
by: Frank Rizzo |
last post by:
Any ideas?
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
Is it possible to alter the string type?
Basicly what i want to do is to create my own string type. lets call it
sqlString, when i use this
it will always use replace on the string assigned...
Instead of using:
| |
by: Christoph Heindl |
last post by:
Hi,
I'm currently struggling with a design decision. One of my classes
(named Attributable) has a protected member of type
std::list<StrongReference<Attribute> >
Basically the list has strong references that point to Attribute's.
In Attributable i want to provide an stl like interface for
bidirectional iterators like:
|
by: T.A. |
last post by:
I understand why it is not safe to inherit from STL containers, but I have
found (in SGI STL documentation) that for example bidirectional_iterator
class can be used to create your own iterator classes by inheriting from
it, ie.
class my_bidirectional_iterator : public bidirectional_iterator<double>
{
...
};
|
by: libsfan01 |
last post by:
Hi all
This js i wrote to switch display on and off of a given element does
not work in ie but it does in ff and safari.
how can i make it work with ie guys?
<script type='text/javascript'>
function switch_display(switchme) {
|
by: GTalbot |
last post by:
Hello fellow comp.infosystems.www.authoring.stylesheets colleagues,
Imagine this situation:
#grand-parent-abs-pos
{
height: 400px;
position: absolute;
width: 600px;
}
|
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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...
|
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: 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.
| |