value class ValBase
{
public:
int a;
};
ref class RefBase
{
public:
int a;
};
int main(array<System::String ^> ^args)
{
RefBase^ RefBase1 = gcnew RefBase; //LEGAL. Ref type Managed Obj created on CLR heap.
ValBase^ ValBase1 = gcnew ValBase; //LEGAL. Value type Managed Obj created on CLR heap.
RefBase* RefBase2 = new RefBase; //ILLEGAL: new cannot be used on Managed Ref Class
ValBase* ValBase2 = new ValBase; //This compiles okay but where is this "Managed Object" stored ? CLR heap or Native heap ?
}
在上次分配中,託管對象存儲在哪裏?我對C++ CLI完全陌生。另外,值類型是否應該使用堆棧語義來提高代碼的效率?即代替ValBase ValBase1 = gcnew ValBase,我應該使用ValBase ValBase1;此管理對象在哪裏存儲?
這是另一個問題,請不要猶豫,在新的問題中提出。 – 2012-01-19 21:34:05