Connecting Tech Pros Worldwide Help | Site Map

Abstract constructor initialisers

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 07:11 PM
major_tom3
Guest
 
Posts: n/a
Default Abstract constructor initialisers


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, 07:12 PM
Ryan Winter
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.