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

List:       kde-devel
Subject:    Re: c++ question: code duplication across classes
From:       Benoît_Jacob <jacob () math ! jussieu ! fr>
Date:       2006-09-22 20:15:33
Message-ID: 200609222215.33265.jacob () math ! jussieu ! fr
[Download RAW message or body]

> Could you paste your class declarations and the using declaration?

I fixed a small test program, just to tell you where I get problems... and now 
it seems that operator= gets inherited! I really don't understand what's 
going on. The C++ specification says that assignment operators of the base 
class aren't visible by default in the subclass, right? So why does the code 
below work? I'm totally puzzled...

----BEGIN CODE------

#include<stdio.h>

template<typename T, typename Derived>
class VectorBase
{
public:
    VectorBase & operator = ( const VectorBase & v );
};

template<typename T, int Size>
class Vector: public VectorBase< T, Vector<T, Size> >
{
    T m_array[Size];

public:
    Vector() {}
};

template<typename T, typename Derived>
VectorBase<T, Derived> &
VectorBase<T, Derived>::operator =
( const VectorBase<T, Derived> & v)
{
    printf("VectorBase::operator=\n");
}

int main( int argc, char *argv[] )
{
    Vector<int, 1> v, w;
    w = v;
    return 0;
}

-------END CODE-----------

And the output is:

VectorBase::operator=

I really don't understand. Of course that's fine for me, but I'd like to make 
sure I understand that part of the C++ language before I use it in code 
that'll end up in KDE...

BTW: Is it OK to hijack kde-devel for general c++ questions? Sorry if it's 
not.

Benoit
 
>> 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