[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: c++ question: code duplication across classes
From:       Michael Olbrich <michael-olbrich () web ! de>
Date:       2006-09-22 17:43:46
Message-ID: 20060922174346.GC20450 () creature ! apm ! etc ! tu-bs ! de
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


On Fri, Sep 22, 2006 at 04:19:20PM +0200, Benoit Jacob wrote:
> So I am doing this CRTP thing, and I have a problem: is there a way that 
> I can put the operators like operator=, +=, -=, ... in the base class? Or 
> am I forced to implement them in each subclass?
> 
> When trying to put them in the base class, I'm running into problems as 
> C++ specifies that operator= doesn't get inherited by default. I read 
> something about the 'using' C++ keyword but that doesn't seem to be 
> compatible with templates.

If I remember correctly (untested):

class Base
{
public:
	Base& operator+=(const Base& other);
};

class Derived : public Base
{
public:
	using Base::operator+=;
...
};

michael


["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic