valueclasses.cpp

来自「C++ Source code from a tutorial」· C++ 代码 · 共 55 行

CPP
55
字号
// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

__value class SmallData {
public:
    int weight;
    int GetData() { return weight * 100; }
};

__value struct QuickInfo {
    int height;
    int width;
};

struct QuickInfo2 {
    int height;
    int width;
};

void Process(Object *obj) {
    Console::WriteLine(obj->GetType());
}

// This is the entry point for this application
int _tmain(void)
{
    SmallData x;
    QuickInfo a;
    a.height = 10;
    QuickInfo2 b;
    b.height = 20;
    x.weight = 10;
    __box SmallData *px = __box(x);
    Process(px);
    px->weight++;
    x= *px;
    Console::WriteLine(x.weight);

    // Generic type for boxed value
    Object *px2 = __box(x);
    __try_cast<SmallData *>(px2)->weight++;
    x = *__try_cast<SmallData *>(px2);
    Console::WriteLine(x.weight);


    // TODO: Please replace the sample code below with your own.
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?