Hello,
Very often we need to name the basetype of a derived type
class D : public B {
typedef B base_type;
// ...
};
When B es a complexe template expression we need to repeat the
complete expression, which is inconvenient and error prono.
class D : public 'very complex
template expression' {
typedef 'very complex
template expression' base_type;
// ...
};
The inmediate solution comes with the use of the preprocesor
#define XXX_BASE 'very complex \
template expression'
class D : public XXX_BASE {
typedef XXX_BASE base_type;
#undef XXX_BASE
// ...
};
Even if this helps to increase maintenability, it is a little bit
artificial. I would like something more C++ oriented. I have defined a
mixin class that defines a typedef to the inherited base class as
follows:
template <typename T>
struct inhetits : public T {
typedef T base_type;
};
This works well with non-template classes
struct B {
typedef int ii;
};
struct D : inhetits<B{
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
But do not compiles when the inherited class is a template
template<typena me T>
struct BT {
typedef T ii;
};
template<typena me T>
struct DT : inhetits<BT<T {
typedef typename base_type::ii jj;
static jj g(jj v) {return v+1;}
};
test.cpp:74: error: `base_type' has not been declared
test.cpp:74: error: expected nested-name-specifier before "ii"
test.cpp:74: error: `ii' does not name a type
test.cpp: In static member function `static jj DT<T>::g(jj)':
test.cpp:75: error: no match for 'operator+' in 'v + 1'
test.cpp: In function `int main()':
Why base_type is not visible? Why this do not works?
Note that the following works:
template<typena me T>
struct D2T : inhetits<B{
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
struct D2 : inhetits<BT<int {
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
FYI, I'm using g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd
0.125)
Sorry if this has already been discused.
Best,
Vicente 2 1607
viboes wrote:
Hello,
Very often we need to name the basetype of a derived type
class D : public B {
typedef B base_type;
// ...
};
When B es a complexe template expression we need to repeat the
complete expression, which is inconvenient and error prono.
class D : public 'very complex
template expression' {
typedef 'very complex
template expression' base_type;
// ...
};
The inmediate solution comes with the use of the preprocesor
#define XXX_BASE 'very complex \
template expression'
class D : public XXX_BASE {
typedef XXX_BASE base_type;
#undef XXX_BASE
// ...
};
Even if this helps to increase maintenability, it is a little bit
artificial. I would like something more C++ oriented. I have defined a
mixin class that defines a typedef to the inherited base class as
follows:
template <typename T>
struct inhetits : public T {
typedef T base_type;
};
This works well with non-template classes
struct B {
typedef int ii;
};
struct D : inhetits<B{
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
But do not compiles when the inherited class is a template
template<typena me T>
struct BT {
typedef T ii;
};
template<typena me T>
struct DT : inhetits<BT<T {
typedef typename base_type::ii jj;
static jj g(jj v) {return v+1;}
};
test.cpp:74: error: `base_type' has not been declared
test.cpp:74: error: expected nested-name-specifier before "ii"
test.cpp:74: error: `ii' does not name a type
test.cpp: In static member function `static jj DT<T>::g(jj)':
test.cpp:75: error: no match for 'operator+' in 'v + 1'
test.cpp: In function `int main()':
Why base_type is not visible? Why this do not works?
It does not work because 'base_type' in your template is called "a
dependent name", and when resolving names (like 'base_type' in your
case) in a template the base classes are _not_ searched. Read the FAQ.
>
Note that the following works:
template<typena me T>
struct D2T : inhetits<B{
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
struct D2 : inhetits<BT<int {
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
FYI, I'm using g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd
0.125)
Sorry if this has already been discused.
It has. Read the FAQ.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On 14 juil, 22:38, Victor Bazarov <v.Abaza...@com Acast.netwrote:
viboes wrote:
Hello,
Very often we need to name the basetype of a derived type
class D : public B {
typedef B base_type;
// ...
};
When B es a complexe template expression we need to repeat the
complete expression, which is inconvenient and error prono.
class D : public 'very complex
template expression' {
typedef 'very complex
template expression' base_type;
// ...
};
The inmediate solution comes with the use of the preprocesor
#define XXX_BASE 'very complex \
template expression'
class D : public XXX_BASE {
typedef XXX_BASE base_type;
#undef XXX_BASE
// ...
};
Even if this helps to increase maintenability, it is a little bit
artificial. I would like something more C++ oriented. I have defined a
mixin class that defines a typedef to the inherited base class as
follows:
template <typename T>
struct inhetits : public T {
typedef T base_type;
};
This works well with non-template classes
struct B {
typedef int ii;
};
struct D : inhetits<B{
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
But do not compiles when the inherited class is a template
template<typena me T>
struct BT {
typedef T ii;
};
template<typena me T>
struct DT : inhetits<BT<T {
typedef typename base_type::ii jj;
static jj g(jj v) {return v+1;}
};
test.cpp:74: error: `base_type' has not been declared
test.cpp:74: error: expected nested-name-specifier before "ii"
test.cpp:74: error: `ii' does not name a type
test.cpp: In static member function `static jj DT<T>::g(jj)':
test.cpp:75: error: no match for 'operator+' in 'v + 1'
test.cpp: In function `int main()':
Why base_type is not visible? Why this do not works?
It does not work because 'base_type' in your template is called "a
dependent name", and when resolving names (like 'base_type' in your
case) in a template the base classes are _not_ searched. Read the FAQ.
Note that the following works:
template<typena me T>
struct D2T : inhetits<B{
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
struct D2 : inhetits<BT<int {
typedef base_type::ii jj;
static jj g(jj v) {return v+1;}
};
FYI, I'm using g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd
0.125)
Sorry if this has already been discused.
It has. Read the FAQ.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks a lot for the pointer.
Vicente This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: zimba |
last post by:
Hello !
If somebody is interested, here is a small hack I've done today.
There are still some curious effects, but I'm pretty satisfied by the
results, since PHP is not very flexible.
Let me know what you think, I'm looking into talking about somethin ;)
|
by: Udo Gleich |
last post by:
Hi,
I try to implement mixin classes. Thats why I
need to make a new class at runtime.
--tmp.py-------------------------------------
import new
class K1(object):
|
by: Mac |
last post by:
I have a MixIn class which defines a method foo(), and is then mixed in
with another class by being prepended to that class's __bases__ member,
thus overriding that class's definition of foo(). In my application
though it is necessary for the MixIn's foo() to call the overridden
foo(). How can I do this?
My current hack is to do this:
def foo(): # MixIn's method
orig_bases = self.__class__.__bases__
|
by: Paolino |
last post by:
I had always been negative on the boldeness of python on insisting that
unbound methods should have been applied only to its im_class instances.
Anyway this time I mixed in rightly, so I post this for comments.
###### looking for a discovery .Start #################
class _Mixin(object):
def __init__(self,main,instance,*args,**kwargs):
# do mixin businnes
main.__reinit__(self,instance) # the caveated interface
|
by: barnesc |
last post by:
>So mixins are just a sub-class of sub-classing?
>
>I've just found this:
>
>
>A mixin class is a parent class that is inherited from - but not as
>a means of specialization. Typically, the mixin will export services to a
>child class, but no semantics will be implied about the child "being a
>kind of" the parent.
>
| |
by: Alex Hunsley |
last post by:
I know that I can catch access to unknown attributes with code something
like the following:
class example:
def __getattr__(self, name):
if name == 'age':
return __age
else:
raise AttributeError
|
by: Ed Leafe |
last post by:
In Dabo, we create cursor classes that combine the backend-specific
dbapi cursor class with our own mixin class that adds framework-
specific behaviors. This has been working well for a couple of years
now with many different backends, but today I'm getting errors with
our Firebird class. I've checked the kinterbasdb site, and found
nothing there that was helpful. The error reads:
TypeError: Error when calling the metaclass bases
type...
|
by: ish |
last post by:
I think this is more of a style question than anything else... I'm
doing a C++ wrapper around a C event library I have and one of the
items is a timer class, I'm also using this task to learn C++.
Is it cleaner to have users subclass my Timer class and implement the
on_timeout() method? Or should the user use a mixin and provide the
mixin to my Timer class?
The subclass method kinda looks like this..
|
by: Ole Nielsby |
last post by:
Given these 3 classes
class A {virtual void a(){}};
class B {virtual void b(){}};
class C: public A, public B {};
I want the offset of B in C, as a size_t value, and preferably as a
constant expression.
I got a solution that seems to work on VC9Express:
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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: 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...
| |