Generic implementation of a smart pointer

  • Thread starter Thread starter software
  • Start date Start date
S

software

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
 
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!

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.
 
public ref class BotPtr : GenericSmartPtr said:
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
 
Back
Top