Connecting Tech Pros Worldwide Help | Site Map

Abstract constructor initialisers

  #1  
Old July 19th, 2005, 08:11 PM
major_tom3
Guest
 
Posts: n/a

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
  #2  
Old July 19th, 2005, 08:12 PM
Ryan Winter
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
Port code from C++ to C? PengYu.UT@gmail.com answers 13 November 14th, 2005 10:50 PM