Re: Extendable envelope/letter idiom
"Anders Logg" <email@example.com> wrote in message
| Wouldn't this require a user of the classes to write something like
| shared_ptr<GenericMatrix> A(new SparseMatrix);
| instead of just
| Matrix A;
You could always start with:
typedef shared_ptr<GenericMatrix> Matrix;
But this obviously has limits...
| Thanks for the comments! Using a standard tool such as boost::shared_ptr<>
| probably better programming practice, but I need to assign high priority
| to the syntax.
The reason I mentioned boost::shared_ptr was that Matrix was
not doing proper memory management (it lacked a copy constructor
and assignment operator that would either copy or otherwise
manage the sharing of the contained GenericMatrix class).
If syntax is important, you could still use a Matrix class,
but consider using a smart pointer internally -- or implement
adequate memory management for a (naked) pointer.
This matrix class could have an additional constructor taking
a pointer to a GenericMatrix.
This way you could write:
Matrix A(bufPtr,rowCount,colCount); // auto-detect best type
Matrix B( new MyClass(....) ); // use custom representation
And users could still provide a custom factory function:
Matrix C( chooseMyBestMatrixFormat(....) );
It is just preferable not to split a class hierarchy
as was the case in the code you posted...
Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
Soft Dev Manger, xitact <> http://www.xitact.com
Brainbench MVP for C++ <> http://www.brainbench.com
|All times are GMT. The time now is 07:51 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.