⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delegate2.cpp

📁 C++ Source code from a tutorial
💻 CPP
字号:
// 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;

__delegate int MyDelegate();

__gc class EventHandlers {
public:
    int test1() { 
        Console::WriteLine("test1");
        return 100; 
    }
    static int test2() { 
        return 200; 
    }
    int test3() { 
        Console::WriteLine("test3");
        return 250;
    }
};

// This is the entry point for this application
int _tmain(void)
{
    // TODO: Please replace the sample code below with your own.
    EventHandlers *handler = new EventHandlers;

    MyDelegate *del = new MyDelegate(handler, &EventHandlers::test1);
    del+= new MyDelegate(handler, EventHandlers::test3);
    Console::WriteLine("===Invoking...");
    Console::WriteLine(del->Invoke());
    Console::WriteLine("===Finished invoking!");

    // Just for kicks, let's look at some of the types
    Type *t = del->GetType();
    Console::WriteLine(t->BaseType);

    MyDelegate *del2 = new MyDelegate(0, &EventHandlers::test2);
    Console::WriteLine(del2->Invoke());
    return 0;
}

⌨️ 快捷键说明

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