Loki::SmartPtr syntax

M

Mosfet

Hi,

I wanted to test the Loki SmartPtr but I don't know exactly how it works
and reading code with so many templates give me headache.
So here is how I am using it :

SmartPtr<Gdiplus::Bitmap> bmp =
new
Gdiplus::Bitmap(rcClient.Width(),rcClient.Height(),PixelFormat16bppRGB565);

SmartPtr<Gdiplus::Graphics> g = Gdiplus::Graphics::FromImage( bmp );

error C2664: 'Gdiplus::Graphics::FromImage' : cannot convert parameter 1
from 'Loki::SmartPtr<T>' to 'Gdiplus::Image *'
1> with
1> [
1> T=Gdiplus::Bitmap
1> ]
1> No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called


Actually how can I get from my SmartPtr<Gdiplus::Bitmap> the underlying
pointer. I tried to do this :

SmartPtr<Gdiplus::Graphics> g = Gdiplus::Graphics::FromImage(
(Image*)&bmp ); and it compiles but I get a crash when running.

Thanks
 
A

Alf P. Steinbach

* Mosfet:
Hi,

I wanted to test the Loki SmartPtr but I don't know exactly how it works
and reading code with so many templates give me headache.
So here is how I am using it :

SmartPtr<Gdiplus::Bitmap> bmp =
new
Gdiplus::Bitmap(rcClient.Width(),rcClient.Height(),PixelFormat16bppRGB565);

SmartPtr<Gdiplus::Graphics> g = Gdiplus::Graphics::FromImage( bmp );

error C2664: 'Gdiplus::Graphics::FromImage' : cannot convert parameter 1
from 'Loki::SmartPtr<T>' to 'Gdiplus::Image *'
1> with
1> [
1> T=Gdiplus::Bitmap
1> ]
1> No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called


Actually how can I get from my SmartPtr<Gdiplus::Bitmap> the underlying
pointer. I tried to do this :

SmartPtr<Gdiplus::Graphics> g = Gdiplus::Graphics::FromImage(
(Image*)&bmp ); and it compiles but I get a crash when running.

When one doesn't understand what's going on, it's seldom a good solution to use
a cast to tell the compiler "I'm completely confident that this is right, so
don't give me any diagnostics please, just do as I say".

For most smart pointers you can get at the contained raw pointer by doing

&*sp

and there's usually also something like

sp.get()

Check out the Loki documentation and/or source code if neither of these work.


Cheers & hth.,

- Alf
 

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top