473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Template class and __nogc

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

Dec 22 '05 #1
3 1063
Stormy wrote:
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
Dec 22 '05 #2
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

Dec 22 '05 #3
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

Dec 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Itay_k | last post by:
Hello, I want a member in my class that will save pointer to pointer to System::Drawing::Image class. When I write on my class code: System::Drawing::Image **bmp; I get this error message:...
1
by: Kevin | last post by:
All samples in Micoroft just mention that if a managed type is used as a member in nongc class, for example: gcroot<String*> is used to define a String managed member variable. What if the managed...
15
by: Edward Diener | last post by:
Why is it impossible to have a __value class instance variable in a __nogc class when it is possible to have a built-in type instance variable in a __nogc class ? __value class X { int a; };...
3
by: Edward Diener | last post by:
I want to share a __nogc classes between different assemblies. For __gc classes, one only needs to declare the class public in order to be able to do this. Is there a way to share a __nogc class so...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
0
by: ajerijian | last post by:
Hi all, My apologies for posting this message into the wrong newsgroup. I'm reposting it here since it's more appropriate. I am attempting to export an unmanaged (__nogc) C++ class from a...
4
by: mccoyn | last post by:
I have a class exported in a dll that has member variables I wish to access. When I do it I get an error C2039: 'myVar' : is not a member of myClass Here is an example of what my code looks like...
0
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
1
by: mschuck | last post by:
Here is the scenario I'm trying to make work. I've got 2 managed C++ classes, each of which wrappes an unmanaged C++ class, kind of like so: __nogc class UnmanagedClassA { public: void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.