Abstract constructor initialisers

M

major_tom3

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 said:
::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.



Thanks,



tom
 
R

Ryan Winter

major_tom3 said:
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.

I have no problems with this implementation.

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

Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top