Connecting Tech Pros Worldwide Forums | Help | Site Map

Abstract constructor initialisers

major_tom3
Guest
 
Posts: n/a
#1: Jul 19 '05

I have a class derived from an abstract base class, which is in turn
derived from a further ABC:

template< typename T > class CAbstractMatrix{...};

template< typename T > class CAbstractSquareMatrix: public
CAbstractMatrix< T >{...};

template< typename T > class CDiagonalMatrix : public
CAbstractSquareMatrix< T >{...};



Can anyone tell me why this constructor initialiser:



template< typename T > CDiagonalMatrix< T >::CDiagonalMatrix( unsigned
long nRows, T* pData, bool bAdopt = false )

: CAbstractSquareMatrix< T >( pData, nRows, bAdopt ) // works

{

...

}



calls CAbstractSquareMatrix< T >::CAbstractSquareMatrix( unsigned long,
T*, bool) as intended, but the latter:



template< typename T > CAbstractSquareMatrix< T[color=blue]
>::CAbstractSquareMatrix( T* pData, unsigned long nSize, bool[/color]

bAdopt = false )

: CAbstractMatrix< T >( pData, nSize, bAdopt ) // doesn't work!

{

...

}



fails to call CAbstractMatrix< T >::CAbstractMatrix( T*, unsigned long,
bool) in its turn? Everything compiles fine; don't be put off by my
changing the order of the parameters between classes. The code fails at
run-time because the base-base-class's constructor is not called.



Thanks,



tom


--
Posted via http://dbforums.com

Ryan Winter
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Abstract constructor initialisers


major_tom3 wrote:
[color=blue]
> I have a class derived from an abstract base class, which is in turn
> derived from a further ABC:
>
> template< typename T > class CAbstractMatrix{...};
>
> template< typename T > class CAbstractSquareMatrix: public
> CAbstractMatrix< T >{...};
>
> template< typename T > class CDiagonalMatrix : public
> CAbstractSquareMatrix< T >{...};
>
> Can anyone tell me why this constructor initialiser:
>
> template< typename T > CDiagonalMatrix< T >::CDiagonalMatrix( unsigned
> long nRows, T* pData, bool bAdopt = false )
> : CAbstractSquareMatrix< T >( pData, nRows, bAdopt ) // works
> {
> ...
> }
>
> calls CAbstractSquareMatrix< T >::CAbstractSquareMatrix( unsigned long,
> T*, bool) as intended, but the latter:
>
> template< typename T > CAbstractSquareMatrix< T >::CAbstractSquareMatrix(
> T* pData, unsigned long nSize, bool bAdopt = false )
> : CAbstractMatrix< T >( pData, nSize, bAdopt ) // doesn't work!
> {
> ...
> }
>
> fails to call CAbstractMatrix< T >::CAbstractMatrix( T*, unsigned long,
> bool) in its turn? Everything compiles fine; don't be put off by my
> changing the order of the parameters between classes. The code fails at
> run-time because the base-base-class's constructor is not called.[/color]

I have no problems with this implementation.

Can you specify the compiler and platform you are using, and also post
working code.

Ryan

Closed Thread


Similar C / C++ bytes