Template class and __nogc

S

Stormy

Can I define a template class as following

#pragma unmanaged
#include "mybaseclass.h"
#pragma managed
namespace mymanaged1
{
namespace mymanaged2
{
namespace myunmanaged
{
template<class T>
__nogc class A :public mybase
{
};
}
}
}
#pragma managed

I got hundreds compile errors, two of them are:
C3151: '__nogc' cannot be applied to a template
C3151: '__gc' cannot be applied to a template

Can anybody tell me why and how to correct it. Thanks
 
C

Carl Daniel [VC++ MVP]

Stormy said:
Can I define a template class as following

#pragma unmanaged
#include "mybaseclass.h"
#pragma managed
namespace mymanaged1
{
namespace mymanaged2
{
namespace myunmanaged
{
template<class T>
__nogc class A :public mybase
{
};
}
}
}
#pragma managed

I got hundreds compile errors, two of them are:
C3151: '__nogc' cannot be applied to a template
C3151: '__gc' cannot be applied to a template

Can anybody tell me why and how to correct it. Thanks

Just get rid of the __nogc. Since the base class is unmanaged,
instantiations of the class will also be unmanaged.

Note that the following compiles regardless of the #pragma unmanaged
surrounding the template usage:

#pragma unmanaged

class B
{
};

#pragma managed
namespace mymanaged1
{
namespace mymanaged2
{
namespace myunmanaged
{
#pragma unmanaged
template<class T>
class A :public B
{
};

A<int> ai;

A<int> __nogc* pai = &ai;
#pragma managed
}
}
}

-cd
 
S

Stormy

Thank you very much for the help,
I've changed and rebuilt my project, this time I got "fatal error
C1506: unrecoverable block scoping error". I looked at error code in
microsoft.com, it is "To fix by checking the following possible causes
-Mismatched braces -Unusually large function or class".
by the way, the case class B is in one of my win32 dlls.

Thanks
 
S

Stormy

Thank you very much for the help,
I've changed and rebuilt my project, this time I got "fatal error
C1506: unrecoverable block scoping error". I looked at error code in
microsoft.com, it is "To fix by checking the following possible causes
-Mismatched braces -Unusually large function or class".
by the way, the case class B is in one of my win32 dlls.

Thanks
 

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

Top