Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

Generic implementation of a smart pointer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
software@werthmesstechnik.de - 09 Oct 2007 13:06 GMT
Hello,

I am a new bee to c++/cli, here's my question: I have a template
version of a smart pointer class I can't use in my application because
I need to use it in more than one assembly. I thought of rewriting the
class as a generic class to avoid this problem. Unfortuneatly it is
not possible to use Pointers inside generic classes.

Code:

generic< typename T> public ref class GenericSmartPtr
{
private:
T* ptr;

public:
GenericSmartPtr() : ptr(nullptr) {}
GenericSmartPtr(T* t) {ptr = t;}
!GenericSmartPtr() {delete ptr;}
~GenericSmartPtr() {this->!GenericSmartPtr();}
}

this compiles with Error C3229
If I'd used template instead of generic this would compile, but cannot
be used outside the assembly, which is necessary.

Please help me your ideas!
Jens
Ben Voigt [C++ MVP] - 09 Oct 2007 15:35 GMT
> Hello,
>
[quoted text clipped - 23 lines]
>
> Please help me your ideas!

I think the best you can do is:

template< typename T> public ref class GenericSmartPtr { ... };

public ref class BotPtr : GenericSmartPtr<Bot> { ... };
public ref class SystemPtr : GenericSmartPtr<System> { ... };

in one assembly, and use the exported non-template types in every other
assembly.
software@werthmesstechnik.de - 09 Oct 2007 17:13 GMT
> public ref class BotPtr : GenericSmartPtr<Bot> { ... };
> public ref class SystemPtr : GenericSmartPtr<System> { ... };
>
> in one assembly, and use the exported non-template types in every other
> assembly.

Hello Ben,

thanks for the hint. It works!

Jens

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.