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