By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,080 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,080 IT Pros & Developers. It's quick & easy.

DotNet wannabe : Declaring MC++ class object in C ++ class - error ?

P: n/a

I've created a new header file in which one will find :

#using <mscorlib.dll>
using namespace System;

__gc class G
{
public:
int k;
int sum(int){return 0;}
};

a really basic managed class.
In the same header file is a normal C++ class definition

class Temp1
{
public:
Temp1(){G *g=new G;}
~Temp1();

};

Now in some old code I have tried

G *g=new G; //fail
Temp1 t; //ok - works as a wrapper class

error C3828: 'G': placement arguments not allowed while creating
instances of managed classes
So why does my wrapper class work in declaring a managed class object
whilst creating it directly cause a compiler error???

Cheers
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Zardoz wrote:
I've created a new header file in which one will find :

#using <mscorlib.dll>
using namespace System;

__gc class G
{
public:
int k;
int sum(int){return 0;}
};

a really basic managed class.
In the same header file is a normal C++ class definition

class Temp1
{
public:
Temp1(){G *g=new G;}
~Temp1();

};

Now in some old code I have tried

G *g=new G; //fail
Temp1 t; //ok - works as a wrapper class

error C3828: 'G': placement arguments not allowed while creating
instances of managed classes

I do not know what you mean, the code:
__gc class G
{
public:
int k;
int sum(int){return 0;}
};
int main()
{
G *g=new G;
}
compiles OK here.

--
Ioannis Vranos
Nov 17 '05 #2

P: n/a
You probably have included an MFC header or some other header that defines
new for you, like in the MFC case to DEBUG_NEW that uses placement syntax to
help debug memory leaks.

You could build a preprocessed file to verify what is happening.

Ronald Laeremans
Visual C++ team

"Zardoz" <me@you.twang> wrote in message
news:jv********************************@4ax.com...

I've created a new header file in which one will find :

#using <mscorlib.dll>
using namespace System;

__gc class G
{
public:
int k;
int sum(int){return 0;}
};

a really basic managed class.
In the same header file is a normal C++ class definition

class Temp1
{
public:
Temp1(){G *g=new G;}
~Temp1();

};

Now in some old code I have tried

G *g=new G; //fail
Temp1 t; //ok - works as a wrapper class

error C3828: 'G': placement arguments not allowed while creating
instances of managed classes
So why does my wrapper class work in declaring a managed class object
whilst creating it directly cause a compiler error???

Cheers

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.